8 #define MAX_CONFIG_LINE 255
9 #define MAX_CONFIG_PATTERN 64
16 gchar *bs_accesspattern;
18 gboolean integrity_check;
21 static GSList *params = NULL;
24 static guint iterations;
25 static gboolean integrity_check = TRUE;
26 static gboolean verbose = FALSE;
27 static gboolean dump = FALSE;
30 handoff (GstElement *element, GstBuffer *buf, GstPad *pad, gpointer data)
32 if (GST_IS_BUFFER (buf)) {
33 if (integrity_check) {
35 guint8 *ptr = GST_BUFFER_DATA (buf);
37 for (i=0; i<GST_BUFFER_SIZE (buf); i++) {
38 if (*ptr++ != count++) {
39 g_print ("data error!\n");
46 g_print ("not a buffer ! %p\n", buf);
50 create_desc (TestParam *param)
54 desc = g_strdup_printf ("%s %s, pattern %s", (param->src_sizetype == 2 ? "fixed" : "random"),
55 (param->src_data == 1 ? "src" : "subbuffer"),
56 param->bs_accesspattern);
61 read_param_file (gchar *filename)
64 gchar line[MAX_CONFIG_LINE+1];
66 gchar pattern[MAX_CONFIG_PATTERN];
67 gint data, sizetype, integrity_check;
71 fp = fopen (filename, "r");
75 scan_str = g_strdup_printf ("%%d %%d %%%ds %%d", MAX_CONFIG_PATTERN-1);
77 while (fgets (line, MAX_CONFIG_LINE, fp)) {
80 if (line[0] == '\n' || line[0] == '#')
83 if (sscanf (line, scan_str, &data, &sizetype, pattern, &integrity_check) != 4) {
84 g_print ("error on line: %d\n", linenr);
89 TestParam *param = g_malloc (sizeof (TestParam));
91 param->src_data = data;
92 param->src_sizetype = sizetype;
93 param->bs_accesspattern = g_strdup (pattern);
94 param->integrity_check = (integrity_check == 0 ? FALSE : TRUE);
96 params = g_slist_append (params, param);
105 run_test (GstBin *pipeline, gint iters)
108 gint maxiters = iters;
109 gint prev_percent = -1;
112 gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
115 gint newvm = vmsize();
118 percent = (gint)((maxiters-iters+1)*100.0/maxiters);
120 if (percent != prev_percent || newvm - vm > VM_THRES) {
121 g_print ("\r%d (delta %d) %.3d%% ", newvm, newvm - vm, percent);
122 prev_percent = percent;
125 gst_bin_iterate (pipeline);
127 if (iters > 0) iters--;
129 gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
135 g_print ("usage: %s [--verbose] [--dump] <paramfile> <iterations>\n", argv[0]);
139 main (int argc, char *argv[])
144 GstElement *pipeline;
149 gst_init (&argc, &argv);
152 while ((arg_walk < argc) && (argv[arg_walk][0] == '-')) {
153 if (!strncmp (argv[arg_walk], "--verbose", 9))
155 else if (!strncmp (argv[arg_walk], "--dump", 6))
158 g_print ("unknown option %s (ignored)\n", argv[arg_walk]);
163 if (argc - arg_walk < 2) {
167 if (!read_param_file (argv[arg_walk])) {
168 g_print ("error reading file %s\n", argv[arg_walk]);
173 iterations = atoi (argv[arg_walk]);
175 pipeline = gst_elementfactory_make ("pipeline", "pipeline");
178 src = gst_elementfactory_make ("fakesrc", "src");
181 sink = gst_elementfactory_make ("fakesink", "sink");
183 g_signal_connect (G_OBJECT (sink), "handoff", G_CALLBACK (handoff), NULL);
185 bs = gst_elementfactory_make ("bstest", "bs");
188 gst_element_connect (src, "src", bs, "sink");
189 gst_element_connect (bs, "src", sink, "sink");
191 gst_bin_add (GST_BIN (pipeline), src);
192 gst_bin_add (GST_BIN (pipeline), bs);
193 gst_bin_add (GST_BIN (pipeline), sink);
199 TestParam *param = (TestParam *) (walk->data);
201 integrity_check = param->integrity_check;
203 g_print ("\n\nrunning test %d (%d iterations):\n", testnum+1, iterations);
204 desc = create_desc (param);
205 g_print ("%s\n", desc);
208 g_object_set (G_OBJECT (src), "data", param->src_data,
209 "sizetype", param->src_sizetype,
210 "filltype", (integrity_check?5:0),
211 "silent", !verbose, NULL);
213 g_object_set (G_OBJECT (bs), "accesspattern", param->bs_accesspattern,
214 "silent", !verbose, NULL);
216 g_object_set (G_OBJECT (sink), "dump", dump,
217 "silent", !verbose, NULL);
219 run_test (GST_BIN (pipeline), iterations);
223 walk = g_slist_next (walk);
226 g_print ("\n\ndone\n");