7 #define MAX_CONFIG_LINE 255
8 #define MAX_CONFIG_PATTERN 64
15 gchar *bs_accesspattern;
17 gboolean integrity_check;
20 static GSList *params = NULL;
23 static guint iterations;
24 static gboolean integrity_check = TRUE;
25 static gboolean verbose = FALSE;
26 static gboolean dump = FALSE;
29 handoff (GstElement *element, GstBuffer *buf, GstPad *pad, gpointer data)
31 if (GST_IS_BUFFER (buf)) {
32 if (integrity_check) {
34 guint8 *ptr = GST_BUFFER_DATA (buf);
36 for (i=0; i<GST_BUFFER_SIZE (buf); i++) {
37 if (*ptr++ != count++) {
38 g_print ("data error!\n");
45 g_print ("not a buffer ! %p\n", buf);
49 create_desc (TestParam *param)
53 desc = g_strdup_printf ("%s %s, pattern %s", (param->src_sizetype == 2 ? "fixed" : "random"),
54 (param->src_data == 1 ? "src" : "subbuffer"),
55 param->bs_accesspattern);
60 read_param_file (gchar *filename)
63 gchar line[MAX_CONFIG_LINE+1];
65 gchar pattern[MAX_CONFIG_PATTERN];
66 gint data, sizetype, integrity_check;
70 fp = fopen (filename, "r");
74 scan_str = g_strdup_printf ("%%d %%d %%%ds %%d", MAX_CONFIG_PATTERN-1);
76 while (fgets (line, MAX_CONFIG_LINE, fp)) {
79 if (line[0] == '\n' || line[0] == '#')
82 if (sscanf (line, scan_str, &data, &sizetype, pattern, &integrity_check) != 4) {
83 g_print ("error on line: %d\n", linenr);
88 TestParam *param = g_malloc (sizeof (TestParam));
90 param->src_data = data;
91 param->src_sizetype = sizetype;
92 param->bs_accesspattern = g_strdup (pattern);
93 param->integrity_check = (integrity_check == 0 ? FALSE : TRUE);
95 params = g_slist_append (params, param);
104 run_test (GstBin *pipeline, gint iters)
107 gint maxiters = iters;
108 gint prev_percent = -1;
111 gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
114 gint newvm = gst_alloc_trace_live_all ();
117 percent = (gint)((maxiters-iters+1)*100.0/maxiters);
119 if (percent != prev_percent || newvm - vm > VM_THRES) {
120 g_print ("\r%d (delta %d) %.3d%% ", newvm, newvm - vm, percent);
121 prev_percent = percent;
124 gst_bin_iterate (pipeline);
126 if (iters > 0) iters--;
128 gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
134 g_print ("usage: %s [--verbose] [--dump] <paramfile> <iterations>\n", argv[0]);
138 main (int argc, char *argv[])
143 GstElement *pipeline;
148 gst_alloc_trace_set_flags_all (GST_ALLOC_TRACE_LIVE);
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_element_factory_make ("pipeline", "pipeline");
178 src = gst_element_factory_make ("fakesrc", "src");
181 sink = gst_element_factory_make ("fakesink", "sink");
183 g_object_set (sink, "signal-handoff", TRUE, NULL);
184 g_signal_connect (G_OBJECT (sink), "handoff", G_CALLBACK (handoff), NULL);
186 bs = gst_element_factory_make ("bstest", "bs");
189 gst_element_link_many (src, bs, sink);
191 gst_bin_add_many (GST_BIN (pipeline), src, bs, sink);
197 TestParam *param = (TestParam *) (walk->data);
199 integrity_check = param->integrity_check;
201 g_print ("\n\nrunning test %d (%d iterations):\n", testnum+1, iterations);
202 desc = create_desc (param);
203 g_print ("%s\n", desc);
206 g_object_set (G_OBJECT (src), "data", param->src_data,
207 "sizetype", param->src_sizetype,
208 "filltype", (integrity_check?5:0),
209 "silent", !verbose, NULL);
211 g_object_set (G_OBJECT (bs), "accesspattern", param->bs_accesspattern,
212 "silent", !verbose, NULL);
214 g_object_set (G_OBJECT (sink), "dump", dump,
215 "silent", !verbose, NULL);
217 run_test (GST_BIN (pipeline), iterations);
221 walk = g_slist_next (walk);
224 g_print ("\n\ndone\n");