Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 4 commits
  • 3 files changed
  • 0 comments
  • 1 contributor
Feb 10, 2012
Werner Almesberger ptest: new options -v and -m to exercise MIDI message processing
-v var  enabled tracing of the specified control variable. This
variable must be a system variable. (This is due to an implementation
detail: we look it up after freeing the symbol table, so only the
system variables survive that long.)

-m [chan.]ctrl=value  injects a MIDI control message into the stimuli
system and prints the value of the traced variable after processing
the message. The -m option can be repeated.
42f7314
Werner Almesberger test/stimin: added MIDI injection to test cases
Also corrected differential -> range test that was actually
range -> range.
1f4cdb9
Werner Almesberger stimuli: ignore value 0 in midi_proc_diff_button
We should probably never receive a zero here. But if we do, ignoring
it seem to be the best choice.
7709d04
Werner Almesberger test/stimin: added differential -> { unbounded, cyclic, button } and …
…button -> toggle

This completes the set of "interesting" mappings.
f398564
76  src/compiler/ptest/ptest.c
@@ -26,6 +26,7 @@
26 26
 static int quiet = 0;
27 27
 static int symbols = 0;
28 28
 static const char *fail = NULL;
  29
+static const char *trace_var = NULL;
29 30
 static const char *buffer;
30 31
 
31 32
 
@@ -332,6 +333,63 @@ static void show_patch(const struct patch *patch)
332 333
 }
333 334
 
334 335
 
  336
+static struct midi {
  337
+	int chan, ctrl, value;
  338
+	struct midi *next;
  339
+} *midi = NULL, **last_midi = &midi;
  340
+
  341
+
  342
+static void add_midi(const char *s)
  343
+{
  344
+	int chan, ctrl, value;
  345
+
  346
+	if (sscanf(s, "%d.%d=%d", &chan, &ctrl, &value) == 3);
  347
+	else if (sscanf(s, "%d=%d", &ctrl, &value) == 2)
  348
+		chan = 1;
  349
+	else {
  350
+		fprintf(stderr, "don't understand \"%s\"\n", s);
  351
+		exit(1);
  352
+	}
  353
+	*last_midi = malloc(sizeof(struct midi));
  354
+	if (!*last_midi) {
  355
+		perror("malloc");
  356
+		exit(1);
  357
+	}
  358
+	(*last_midi)->chan = chan;
  359
+	(*last_midi)->ctrl = ctrl;
  360
+	(*last_midi)->value = value;
  361
+	(*last_midi)->next = NULL;
  362
+	last_midi = &(*last_midi)->next;
  363
+}
  364
+
  365
+
  366
+static void play_midi(struct patch *patch)
  367
+{
  368
+	struct sym *sym;
  369
+	float f = 0;
  370
+
  371
+	sym = unique(trace_var);
  372
+	if (!sym) {
  373
+		fprintf(stderr, "can't find trace variable \"%s\"\n",
  374
+		    trace_var);
  375
+		exit(1);
  376
+	}
  377
+	if (!sym->stim_regs) {
  378
+		fprintf(stderr, "\"%s\" is not a control variable\n",
  379
+		    trace_var);
  380
+		exit(1);
  381
+	}
  382
+	sym->stim_regs->pfv = &f;
  383
+
  384
+	while (midi) {
  385
+		stim_midi_ctrl(patch->stim,
  386
+		    midi->chan, midi->ctrl, midi->value);
  387
+		printf("%g\n", f);
  388
+		midi = midi->next;
  389
+	}
  390
+}
  391
+
  392
+
335 393
 static void compile(const char *pgm)
336 394
 {
337 395
 	struct patch *patch;
@@ -341,6 +399,8 @@ static void compile(const char *pgm)
341 399
 		exit(1);
342 400
 	if (!quiet)
343 401
 		show_patch(patch);
  402
+	if (trace_var)
  403
+		play_midi(patch);
344 404
 	/*
345 405
 	 * We can't use patch_free here because that function also accesses
346 406
 	 * image data, which isn't available in standalone builds. A simple
@@ -417,15 +477,19 @@ static void free_buffer(void)
417 477
 static void usage(const char *name)
418 478
 {
419 479
 	fprintf(stderr,
420  
-"usage: %s [-c [-c]|-f error] [-n runs] [-q] [-s] [-Wwarning...] [expr]\n\n"
  480
+"usage: %s [-c [-c]|-f error] [-m [chan.]ctrl=value ...] [-n runs]\n"
  481
+"       %*s [-q] [-s] [-v var] [-Wwarning ...] [expr]\n\n"
421 482
 "  -c        generate code and dump generated code (unless -q is set)\n"
422 483
 "  -c -c     generate and dump VM code\n"
423 484
 "  -f error  fail any assignment with specified error message\n"
  485
+"  -m [chan.]ctrl=value\n"
  486
+"            send a MIDI message to the stimuli subsystem\n"
424 487
 "  -n runs   run compilation repeatedly (default: run only once)\n"
425 488
 "  -q        quiet operation\n"
426 489
 "  -s        dump symbol table after parsing (only if -c is not set)\n"
  490
+"  -v var    trace the specified variable (used with -m)\n"
427 491
 "  -Wwarning enable compiler warning (one of: section, undefined)\n"
428  
-    , name);
  492
+    , name, (int) strlen(name), "");
429 493
 	exit(1);
430 494
 }
431 495
 
@@ -440,7 +504,7 @@ int main(int argc, char **argv)
440 504
 	warn_section = 0;
441 505
 	warn_undefined = 0;
442 506
 
443  
-	while ((c = getopt(argc, argv, "cf:n:qsW:")) != EOF)
  507
+	while ((c = getopt(argc, argv, "cf:m:n:qsv:W:")) != EOF)
444 508
 		switch (c) {
445 509
 		case 'c':
446 510
 			codegen++;
@@ -448,6 +512,9 @@ int main(int argc, char **argv)
448 512
 		case 'f':
449 513
 			fail = optarg;
450 514
 			break;
  515
+		case 'm':
  516
+			add_midi(optarg);
  517
+			break;
451 518
 		case 'n':
452 519
 			repeat = strtoul(optarg, &end, 0);
453 520
 			if (*end)
@@ -459,6 +526,9 @@ int main(int argc, char **argv)
459 526
 		case 's':
460 527
 			symbols = 1;
461 528
 			break;
  529
+		case 'v':
  530
+			trace_var = optarg;
  531
+			break;
462 532
 		case 'W':
463 533
 			if (!strcmp(optarg, "section"))
464 534
 				warn_section = 1;
144  src/compiler/test/stimin
@@ -3,79 +3,187 @@
3 3
 
4 4
 ###############################################################################
5 5
 
6  
-ptest "stimuli, input, MIDI: range -> range" -c -q << EOF
  6
+ptest "stimuli, input, MIDI: range -> range" -c -q \
  7
+    -v sx -m 0=63 -m 0=127 -m 0=0 <<EOF
7 8
 midi "foo" { bar = range(1, 0); }
8  
-var = range(bar);
  9
+sx = range(bar);
9 10
 EOF
10 11
 expect <<EOF
  12
+0.496063
  13
+1
  14
+0
11 15
 EOF
12 16
 
13 17
 #------------------------------------------------------------------------------
14 18
 
15  
-ptest "stimuli, input, MIDI: range -> unbounded" -c -q << EOF
  19
+ptest "stimuli, input, MIDI: range -> unbounded" -c -q \
  20
+    -v sx -m 0=64 -m 0=127 -m 0=0 <<EOF
16 21
 midi "foo" { bar = range(1, 0); }
17  
-var = unbounded(bar);
  22
+sx = unbounded(bar);
18 23
 EOF
19 24
 expect <<EOF
  25
+0.503937
  26
+1
  27
+0
20 28
 EOF
21 29
 
22 30
 #------------------------------------------------------------------------------
23 31
 
24  
-ptest "stimuli, input, MIDI: range -> cyclic" -c -q << EOF
  32
+ptest "stimuli, input, MIDI: range -> cyclic" -c -q \
  33
+    -v sx -m 0=63 -m 0=127 -m 0=0 <<EOF
25 34
 midi "foo" { bar = range(1, 0); }
26  
-var = cyclic(bar);
  35
+sx = cyclic(bar);
27 36
 EOF
28 37
 expect <<EOF
  38
+0.496063
  39
+1
  40
+0
29 41
 EOF
30 42
 
31 43
 #------------------------------------------------------------------------------
32 44
 
33  
-ptest "stimuli, input, MIDI: range -> button" -c -q << EOF
  45
+ptest "stimuli, input, MIDI: range -> button" -c -q \
  46
+    -v sx -m 0=63 -m 0=127 -m 0=0 <<EOF
34 47
 midi "foo" { bar = range(1, 0); }
35  
-var = button(bar);
  48
+sx = button(bar);
36 49
 EOF
37 50
 expect <<EOF
  51
+1
  52
+1
  53
+0
38 54
 EOF
39 55
 
40 56
 #------------------------------------------------------------------------------
41 57
 
42  
-ptest "stimuli, input, MIDI: range -> toggle" -c -q << EOF
  58
+ptest "stimuli, input, MIDI: range -> toggle" -c -q \
  59
+    -v sx -m 0=63 -m 0=127 -m 0=0 <<EOF
43 60
 midi "foo" { bar = range(1, 0); }
44  
-var = toggle(bar);
  61
+sx = toggle(bar);
45 62
 EOF
46 63
 expect <<EOF
  64
+1
  65
+1
  66
+0
47 67
 EOF
48 68
 
49 69
 #------------------------------------------------------------------------------
50 70
 
51  
-ptest "stimuli, input, MIDI: differential -> range" -c -q << EOF
52  
-midi "foo" { bar = range(1, 0); }
53  
-var = range(bar);
  71
+ptest "stimuli, input, MIDI: differential -> range" -c -q \
  72
+    -v sx -m 0=127 -m 0=63 -m 0=0 -m 0=63 -m 0=63 -m 0=64 -m 0=66 -m 0=64 <<EOF
  73
+midi "foo" { bar = differential(1, 0); }
  74
+sx = range(bar);
  75
+EOF
  76
+expect <<EOF
  77
+0
  78
+0.496063
  79
+0.496063
  80
+0.992126
  81
+1
  82
+0.496063
  83
+0.00787402
  84
+0
  85
+EOF
  86
+
  87
+#------------------------------------------------------------------------------
  88
+
  89
+ptest "stimuli, input, MIDI: differential -> unbounded" -c -q \
  90
+    -v sx -m 0=127 -m 0=63 -m 0=0 -m 0=63 -m 0=63 -m 0=64 -m 0=66 -m 0=64 <<EOF
  91
+midi "foo" { bar = differential(1, 0); }
  92
+sx = unbounded(bar);
  93
+EOF
  94
+expect <<EOF
  95
+-0.00787402
  96
+0.488189
  97
+0.488189
  98
+0.984252
  99
+1.48031
  100
+0.976378
  101
+0.488189
  102
+-0.015748
  103
+EOF
  104
+
  105
+#------------------------------------------------------------------------------
  106
+
  107
+ptest "stimuli, input, MIDI: differential -> cyclic" -c -q \
  108
+    -v sx -m 0=127 -m 0=63 -m 0=0 -m 0=63 -m 0=63 -m 0=64 -m 0=66 -m 0=64 <<EOF
  109
+midi "foo" { bar = differential(1, 0); }
  110
+sx = cyclic(bar);
54 111
 EOF
55 112
 expect <<EOF
  113
+1
  114
+0.488189
  115
+0.488189
  116
+0.984252
  117
+0.472441
  118
+0.976378
  119
+0.488189
  120
+0.992126
56 121
 EOF
57 122
 
58 123
 #------------------------------------------------------------------------------
59 124
 
60  
-ptest "stimuli, input, MIDI: button -> button" -c -q << EOF
  125
+ptest "stimuli, input, MIDI: differential -> button" -c -q \
  126
+    -v sx -m 0=127 -m 0=63 -m 0=0 -m 0=63 -m 0=63 -m 0=64 -m 0=0 -m 0=64 <<EOF
  127
+midi "foo" { bar = differential(1, 0); }
  128
+sx = button(bar);
  129
+EOF
  130
+expect <<EOF
  131
+0
  132
+1
  133
+1
  134
+1
  135
+1
  136
+0
  137
+0
  138
+0
  139
+EOF
  140
+
  141
+#------------------------------------------------------------------------------
  142
+
  143
+ptest "stimuli, input, MIDI: button -> button" -c -q \
  144
+    -v sx -m 0=127 -m 0=0 -m 0=127 -m 0=0 <<EOF
61 145
 midi "foo" { bar = button(1, 0); }
62  
-var = button(bar);
  146
+sx = button(bar);
  147
+EOF
  148
+expect <<EOF
  149
+1
  150
+0
  151
+1
  152
+0
  153
+EOF
  154
+
  155
+#------------------------------------------------------------------------------
  156
+
  157
+ptest "stimuli, input, MIDI: button -> toggle" -c -q \
  158
+    -v sx -m 0=127 -m 0=0 -m 0=127 -m 0=0 -m 0=127 <<EOF
  159
+midi "foo" { bar = button(1, 0); }
  160
+sx = toggle(bar);
63 161
 EOF
64 162
 expect <<EOF
  163
+1
  164
+1
  165
+0
  166
+0
  167
+1
65 168
 EOF
66 169
 
67 170
 #------------------------------------------------------------------------------
68 171
 
69  
-ptest "stimuli, input, MIDI: toggle -> range" -c -q << EOF
  172
+ptest "stimuli, input, MIDI: toggle -> range" -c -q \
  173
+    -v sx -m 0=127 -m 0=0 -m 0=127 -m 0=0 <<EOF
70 174
 midi "foo" { bar = toggle(1, 0); }
71  
-var = range(bar);
  175
+sx = range(bar);
72 176
 EOF
73 177
 expect <<EOF
  178
+1
  179
+0
  180
+1
  181
+0
74 182
 EOF
75 183
 
76 184
 #------------------------------------------------------------------------------
77 185
 
78  
-ptest_fail "stimuli, input, MIDI: toggle -> button" -c -q << EOF
  186
+ptest_fail "stimuli, input, MIDI: toggle -> button" -c -q <<EOF
79 187
 midi "foo" { bar = toggle(1, 0); }
80 188
 var = button(bar);
81 189
 EOF
2  src/renderer/stimuli.c
@@ -85,6 +85,8 @@ static void midi_proc_range_button(struct s_midi_ctrl *ct, int value)
85 85
 
86 86
 static void midi_proc_diff_button(struct s_midi_ctrl *ct, int value)
87 87
 {
  88
+	if(!value)
  89
+		return;
88 90
 	if(value & 0x40)
89 91
 		regs_set(&ct->regs, 0);
90 92
 	else

No commit comments for this range

Something went wrong with that request. Please try again.