Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: m-labs/flickernoise
base: d68317a
...
head fork: m-labs/flickernoise
compare: f398564
  • 4 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Commits on Feb 10, 2012
Werner Almesberger wpwrak 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 wpwrak test/stimin: added MIDI injection to test cases
Also corrected differential -> range test that was actually
range -> range.
1f4cdb9
Werner Almesberger wpwrak 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 wpwrak test/stimin: added differential -> { unbounded, cyclic, button } and …
…button -> toggle

This completes the set of "interesting" mappings.
f398564
76 src/compiler/ptest/ptest.c
View
@@ -26,6 +26,7 @@
static int quiet = 0;
static int symbols = 0;
static const char *fail = NULL;
+static const char *trace_var = NULL;
static const char *buffer;
@@ -332,6 +333,63 @@ static void show_patch(const struct patch *patch)
}
+static struct midi {
+ int chan, ctrl, value;
+ struct midi *next;
+} *midi = NULL, **last_midi = &midi;
+
+
+static void add_midi(const char *s)
+{
+ int chan, ctrl, value;
+
+ if (sscanf(s, "%d.%d=%d", &chan, &ctrl, &value) == 3);
+ else if (sscanf(s, "%d=%d", &ctrl, &value) == 2)
+ chan = 1;
+ else {
+ fprintf(stderr, "don't understand \"%s\"\n", s);
+ exit(1);
+ }
+ *last_midi = malloc(sizeof(struct midi));
+ if (!*last_midi) {
+ perror("malloc");
+ exit(1);
+ }
+ (*last_midi)->chan = chan;
+ (*last_midi)->ctrl = ctrl;
+ (*last_midi)->value = value;
+ (*last_midi)->next = NULL;
+ last_midi = &(*last_midi)->next;
+}
+
+
+static void play_midi(struct patch *patch)
+{
+ struct sym *sym;
+ float f = 0;
+
+ sym = unique(trace_var);
+ if (!sym) {
+ fprintf(stderr, "can't find trace variable \"%s\"\n",
+ trace_var);
+ exit(1);
+ }
+ if (!sym->stim_regs) {
+ fprintf(stderr, "\"%s\" is not a control variable\n",
+ trace_var);
+ exit(1);
+ }
+ sym->stim_regs->pfv = &f;
+
+ while (midi) {
+ stim_midi_ctrl(patch->stim,
+ midi->chan, midi->ctrl, midi->value);
+ printf("%g\n", f);
+ midi = midi->next;
+ }
+}
+
+
static void compile(const char *pgm)
{
struct patch *patch;
@@ -341,6 +399,8 @@ static void compile(const char *pgm)
exit(1);
if (!quiet)
show_patch(patch);
+ if (trace_var)
+ play_midi(patch);
/*
* We can't use patch_free here because that function also accesses
* image data, which isn't available in standalone builds. A simple
@@ -417,15 +477,19 @@ static void free_buffer(void)
static void usage(const char *name)
{
fprintf(stderr,
-"usage: %s [-c [-c]|-f error] [-n runs] [-q] [-s] [-Wwarning...] [expr]\n\n"
+"usage: %s [-c [-c]|-f error] [-m [chan.]ctrl=value ...] [-n runs]\n"
+" %*s [-q] [-s] [-v var] [-Wwarning ...] [expr]\n\n"
" -c generate code and dump generated code (unless -q is set)\n"
" -c -c generate and dump VM code\n"
" -f error fail any assignment with specified error message\n"
+" -m [chan.]ctrl=value\n"
+" send a MIDI message to the stimuli subsystem\n"
" -n runs run compilation repeatedly (default: run only once)\n"
" -q quiet operation\n"
" -s dump symbol table after parsing (only if -c is not set)\n"
+" -v var trace the specified variable (used with -m)\n"
" -Wwarning enable compiler warning (one of: section, undefined)\n"
- , name);
+ , name, (int) strlen(name), "");
exit(1);
}
@@ -440,7 +504,7 @@ int main(int argc, char **argv)
warn_section = 0;
warn_undefined = 0;
- while ((c = getopt(argc, argv, "cf:n:qsW:")) != EOF)
+ while ((c = getopt(argc, argv, "cf:m:n:qsv:W:")) != EOF)
switch (c) {
case 'c':
codegen++;
@@ -448,6 +512,9 @@ int main(int argc, char **argv)
case 'f':
fail = optarg;
break;
+ case 'm':
+ add_midi(optarg);
+ break;
case 'n':
repeat = strtoul(optarg, &end, 0);
if (*end)
@@ -459,6 +526,9 @@ int main(int argc, char **argv)
case 's':
symbols = 1;
break;
+ case 'v':
+ trace_var = optarg;
+ break;
case 'W':
if (!strcmp(optarg, "section"))
warn_section = 1;
144 src/compiler/test/stimin
View
@@ -3,79 +3,187 @@
###############################################################################
-ptest "stimuli, input, MIDI: range -> range" -c -q << EOF
+ptest "stimuli, input, MIDI: range -> range" -c -q \
+ -v sx -m 0=63 -m 0=127 -m 0=0 <<EOF
midi "foo" { bar = range(1, 0); }
-var = range(bar);
+sx = range(bar);
EOF
expect <<EOF
+0.496063
+1
+0
EOF
#------------------------------------------------------------------------------
-ptest "stimuli, input, MIDI: range -> unbounded" -c -q << EOF
+ptest "stimuli, input, MIDI: range -> unbounded" -c -q \
+ -v sx -m 0=64 -m 0=127 -m 0=0 <<EOF
midi "foo" { bar = range(1, 0); }
-var = unbounded(bar);
+sx = unbounded(bar);
EOF
expect <<EOF
+0.503937
+1
+0
EOF
#------------------------------------------------------------------------------
-ptest "stimuli, input, MIDI: range -> cyclic" -c -q << EOF
+ptest "stimuli, input, MIDI: range -> cyclic" -c -q \
+ -v sx -m 0=63 -m 0=127 -m 0=0 <<EOF
midi "foo" { bar = range(1, 0); }
-var = cyclic(bar);
+sx = cyclic(bar);
EOF
expect <<EOF
+0.496063
+1
+0
EOF
#------------------------------------------------------------------------------
-ptest "stimuli, input, MIDI: range -> button" -c -q << EOF
+ptest "stimuli, input, MIDI: range -> button" -c -q \
+ -v sx -m 0=63 -m 0=127 -m 0=0 <<EOF
midi "foo" { bar = range(1, 0); }
-var = button(bar);
+sx = button(bar);
EOF
expect <<EOF
+1
+1
+0
EOF
#------------------------------------------------------------------------------
-ptest "stimuli, input, MIDI: range -> toggle" -c -q << EOF
+ptest "stimuli, input, MIDI: range -> toggle" -c -q \
+ -v sx -m 0=63 -m 0=127 -m 0=0 <<EOF
midi "foo" { bar = range(1, 0); }
-var = toggle(bar);
+sx = toggle(bar);
EOF
expect <<EOF
+1
+1
+0
EOF
#------------------------------------------------------------------------------
-ptest "stimuli, input, MIDI: differential -> range" -c -q << EOF
-midi "foo" { bar = range(1, 0); }
-var = range(bar);
+ptest "stimuli, input, MIDI: differential -> range" -c -q \
+ -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
+midi "foo" { bar = differential(1, 0); }
+sx = range(bar);
+EOF
+expect <<EOF
+0
+0.496063
+0.496063
+0.992126
+1
+0.496063
+0.00787402
+0
+EOF
+
+#------------------------------------------------------------------------------
+
+ptest "stimuli, input, MIDI: differential -> unbounded" -c -q \
+ -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
+midi "foo" { bar = differential(1, 0); }
+sx = unbounded(bar);
+EOF
+expect <<EOF
+-0.00787402
+0.488189
+0.488189
+0.984252
+1.48031
+0.976378
+0.488189
+-0.015748
+EOF
+
+#------------------------------------------------------------------------------
+
+ptest "stimuli, input, MIDI: differential -> cyclic" -c -q \
+ -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
+midi "foo" { bar = differential(1, 0); }
+sx = cyclic(bar);
EOF
expect <<EOF
+1
+0.488189
+0.488189
+0.984252
+0.472441
+0.976378
+0.488189
+0.992126
EOF
#------------------------------------------------------------------------------
-ptest "stimuli, input, MIDI: button -> button" -c -q << EOF
+ptest "stimuli, input, MIDI: differential -> button" -c -q \
+ -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
+midi "foo" { bar = differential(1, 0); }
+sx = button(bar);
+EOF
+expect <<EOF
+0
+1
+1
+1
+1
+0
+0
+0
+EOF
+
+#------------------------------------------------------------------------------
+
+ptest "stimuli, input, MIDI: button -> button" -c -q \
+ -v sx -m 0=127 -m 0=0 -m 0=127 -m 0=0 <<EOF
midi "foo" { bar = button(1, 0); }
-var = button(bar);
+sx = button(bar);
+EOF
+expect <<EOF
+1
+0
+1
+0
+EOF
+
+#------------------------------------------------------------------------------
+
+ptest "stimuli, input, MIDI: button -> toggle" -c -q \
+ -v sx -m 0=127 -m 0=0 -m 0=127 -m 0=0 -m 0=127 <<EOF
+midi "foo" { bar = button(1, 0); }
+sx = toggle(bar);
EOF
expect <<EOF
+1
+1
+0
+0
+1
EOF
#------------------------------------------------------------------------------
-ptest "stimuli, input, MIDI: toggle -> range" -c -q << EOF
+ptest "stimuli, input, MIDI: toggle -> range" -c -q \
+ -v sx -m 0=127 -m 0=0 -m 0=127 -m 0=0 <<EOF
midi "foo" { bar = toggle(1, 0); }
-var = range(bar);
+sx = range(bar);
EOF
expect <<EOF
+1
+0
+1
+0
EOF
#------------------------------------------------------------------------------
-ptest_fail "stimuli, input, MIDI: toggle -> button" -c -q << EOF
+ptest_fail "stimuli, input, MIDI: toggle -> button" -c -q <<EOF
midi "foo" { bar = toggle(1, 0); }
var = button(bar);
EOF
2  src/renderer/stimuli.c
View
@@ -85,6 +85,8 @@ static void midi_proc_range_button(struct s_midi_ctrl *ct, int value)
static void midi_proc_diff_button(struct s_midi_ctrl *ct, int value)
{
+ if(!value)
+ return;
if(value & 0x40)
regs_set(&ct->regs, 0);
else

No commit comments for this range

Something went wrong with that request. Please try again.