summaryrefslogtreecommitdiff
path: root/bootloader/midi/test
diff options
context:
space:
mode:
authorbzztbomb <skinny@knowhere.net>2011-04-05 19:57:16 -0700
committerbzztbomb <skinny@knowhere.net>2011-04-05 19:57:16 -0700
commit73e16950d73578900d54f3470b57402a9e908c30 (patch)
tree4e24dd9b04bd432139c3ed61866459ac77e4024a /bootloader/midi/test
parent6827a350052baf3999cfa336411f5ec89bb9e769 (diff)
Public firmware release.
Diffstat (limited to 'bootloader/midi/test')
-rw-r--r--bootloader/midi/test/.gitignore3
-rw-r--r--bootloader/midi/test/Makefile28
-rw-r--r--bootloader/midi/test/avr/interrupt.h27
-rw-r--r--bootloader/midi/test/dummy_device.c222
-rw-r--r--bootloader/midi/test/dummy_device.h0
-rw-r--r--bootloader/midi/test/sysex_test.c79
6 files changed, 359 insertions, 0 deletions
diff --git a/bootloader/midi/test/.gitignore b/bootloader/midi/test/.gitignore
new file mode 100644
index 0000000..9d58ef3
--- /dev/null
+++ b/bootloader/midi/test/.gitignore
@@ -0,0 +1,3 @@
+test
+sysex_test
+dummy_test
diff --git a/bootloader/midi/test/Makefile b/bootloader/midi/test/Makefile
new file mode 100644
index 0000000..03547b6
--- /dev/null
+++ b/bootloader/midi/test/Makefile
@@ -0,0 +1,28 @@
+CFLAGS += -I. -I../ -g -Wall -DDEBUG
+DUMMY_SRC = dummy_device.c ../midi.c ../midi_device.c ../bytequeue/bytequeue.c ../bytequeue/interrupt_setting.c
+DUMMY_OBJ = ${DUMMY_SRC:.c=.o}
+
+SYSEX_SRC = sysex_test.c ../sysex_tools.c
+SYSEX_OBJ = ${SYSEX_SRC:.c=.o}
+
+.c.o:
+ @echo CC $<
+ @$(CC) -c $(CFLAGS) -o $*.o $<
+
+dummy_test: clean $(DUMMY_OBJ)
+ @$(CC) -o dummy_test $(DUMMY_OBJ)
+
+sysex_test: clean $(SYSEX_OBJ)
+ @$(CC) -o sysex_test $(SYSEX_OBJ)
+
+run_tests: sysex_test dummy_test
+ ./dummy_test
+ ./sysex_test
+
+all: run_tests
+
+#-------------------
+clean:
+ rm -f *.o *.map *.out *.hex *.tar.gz ../*.o ../bytequeue/*.o dummy_test sysex_test
+#-------------------
+
diff --git a/bootloader/midi/test/avr/interrupt.h b/bootloader/midi/test/avr/interrupt.h
new file mode 100644
index 0000000..8770647
--- /dev/null
+++ b/bootloader/midi/test/avr/interrupt.h
@@ -0,0 +1,27 @@
+//midi for embedded chips,
+//Copyright 2010 Alex Norman
+//
+//This file is part of avr-midi.
+//
+//avr-midi is free software: you can redistribute it and/or modify
+//it under the terms of the GNU General Public License as published by
+//the Free Software Foundation, either version 3 of the License, or
+//(at your option) any later version.
+//
+//avr-midi is distributed in the hope that it will be useful,
+//but WITHOUT ANY WARRANTY; without even the implied warranty of
+//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+//GNU General Public License for more details.
+//
+//You should have received a copy of the GNU General Public License
+//along with avr-midi. If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef FAKE_AVR_INTERRUPTS_H
+#define FAKE_AVR_INTERRUPTS_H
+
+static uint8_t SREG = 0;
+
+void cli(void) {
+}
+
+#endif
diff --git a/bootloader/midi/test/dummy_device.c b/bootloader/midi/test/dummy_device.c
new file mode 100644
index 0000000..268b5ca
--- /dev/null
+++ b/bootloader/midi/test/dummy_device.c
@@ -0,0 +1,222 @@
+//midi for embedded chips,
+//Copyright 2010 Alex Norman
+//
+//This file is part of avr-midi.
+//
+//avr-midi is free software: you can redistribute it and/or modify
+//it under the terms of the GNU General Public License as published by
+//the Free Software Foundation, either version 3 of the License, or
+//(at your option) any later version.
+//
+//avr-midi is distributed in the hope that it will be useful,
+//but WITHOUT ANY WARRANTY; without even the implied warranty of
+//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+//GNU General Public License for more details.
+//
+//You should have received a copy of the GNU General Public License
+//along with avr-midi. If not, see <http://www.gnu.org/licenses/>.
+
+#include "midi_device.h"
+#include "midi.h"
+#include <stdio.h>
+#include <assert.h>
+
+MidiDevice test_device;
+
+uint8_t sent[3];
+uint8_t got[3];
+
+bool cc_called;
+bool noteon_called;
+bool noteoff_called;
+bool aftertouch_called;
+bool pitchbend_called;
+bool songposition_called;
+bool progchange_called;
+bool chanpressure_called;
+bool songselect_called;
+bool tc_quarterframe_called;
+bool realtime_called;
+bool tunerequest_called;
+bool fallthrough_called;
+
+void send_func(MidiDevice * device, uint8_t cnt, uint8_t byte0, uint8_t byte1, uint8_t byte2) {
+ sent[0] = byte0;
+ sent[1] = byte1;
+ sent[2] = byte0;
+ printf("sent: ");
+ uint8_t i;
+ for (i = 0; i < cnt; i++) {
+ printf("%02x ", sent[i]);
+ }
+ printf("\n");
+}
+
+void cc_callback(MidiDevice * device, uint8_t byte0, uint8_t byte1, uint8_t byte2){
+ cc_called = true;
+ got[0] = byte0;
+ got[1] = byte1;
+ got[2] = byte2;
+}
+void noteon_callback(MidiDevice * device, uint8_t byte0, uint8_t byte1, uint8_t byte2){
+ noteon_called = true;
+ got[0] = byte0;
+ got[1] = byte1;
+ got[2] = byte2;
+}
+void noteoff_callback(MidiDevice * device, uint8_t byte0, uint8_t byte1, uint8_t byte2){
+ noteoff_called = true;
+ got[0] = byte0;
+ got[1] = byte1;
+ got[2] = byte2;
+}
+void aftertouch_callback(MidiDevice * device, uint8_t byte0, uint8_t byte1, uint8_t byte2){
+ aftertouch_called = true;
+ got[0] = byte0;
+ got[1] = byte1;
+ got[2] = byte2;
+}
+void pitchbend_callback(MidiDevice * device, uint8_t byte0, uint8_t byte1, uint8_t byte2){
+ pitchbend_called = true;
+ got[0] = byte0;
+ got[1] = byte1;
+ got[2] = byte2;
+}
+void songposition_callback(MidiDevice * device, uint8_t byte0, uint8_t byte1, uint8_t byte2){
+ songposition_called = true;
+ got[0] = byte0;
+ got[1] = byte1;
+ got[2] = byte2;
+}
+
+void progchange_callback(MidiDevice * device, uint8_t byte0, uint8_t byte1){
+ progchange_called = true;
+ got[0] = byte0;
+ got[1] = byte1;
+}
+void chanpressure_callback(MidiDevice * device, uint8_t byte0, uint8_t byte1){
+ chanpressure_called = true;
+ got[0] = byte0;
+ got[1] = byte1;
+}
+void songselect_callback(MidiDevice * device, uint8_t byte0, uint8_t byte1){
+ songselect_called = true;
+ got[0] = byte0;
+ got[1] = byte1;
+}
+void tc_quarterframe_callback(MidiDevice * device, uint8_t byte0, uint8_t byte1){
+ tc_quarterframe_called = true;
+ got[0] = byte0;
+ got[1] = byte1;
+}
+
+void realtime_callback(MidiDevice * device, uint8_t byte){
+ realtime_called = true;
+ got[0] = byte;
+}
+void tunerequest_callback(MidiDevice * device, uint8_t byte){
+ tunerequest_called = true;
+ got[0] = byte;
+}
+
+void fallthrough_callback(MidiDevice * device, uint8_t cnt, uint8_t byte0, uint8_t byte1, uint8_t byte2){
+ fallthrough_called = true;
+ got[0] = byte0;
+ got[1] = byte1;
+ got[2] = byte2;
+}
+
+void reset() {
+ uint8_t i;
+ for(i = 0; i < 3; i++)
+ got[i] = sent[i] = 0;
+ cc_called = false;
+ noteon_called = false;
+ noteoff_called = false;
+ aftertouch_called = false;
+ pitchbend_called = false;
+ songposition_called = false;
+ progchange_called = false;
+ chanpressure_called = false;
+ songselect_called = false;
+ tc_quarterframe_called = false;
+ realtime_called = false;
+ tunerequest_called = false;
+ fallthrough_called = false;
+}
+
+bool anything_called() {
+ return cc_called ||
+ noteon_called ||
+ noteoff_called ||
+ aftertouch_called ||
+ pitchbend_called ||
+ songposition_called ||
+ progchange_called ||
+ chanpressure_called ||
+ songselect_called ||
+ tc_quarterframe_called ||
+ realtime_called ||
+ tunerequest_called ||
+ fallthrough_called;
+}
+
+int main(void) {
+ midi_device_init(&test_device);
+ midi_device_set_send_func(&test_device, send_func);
+
+ midi_send_cc(&test_device, 0, 0, 1);
+ midi_send_cc(&test_device, 15, 1, 1);
+
+ midi_register_fallthrough_callback(&test_device, fallthrough_callback);
+ midi_register_realtime_callback(&test_device, realtime_callback);
+
+ assert(!fallthrough_called);
+ assert(!realtime_called);
+ midi_device_input(&test_device, 3, 0xB0, 0, 1);
+ midi_device_input(&test_device, 1, MIDI_CLOCK, 0, 0);
+ midi_device_process(&test_device);
+ assert(fallthrough_called);
+ assert(realtime_called);
+
+ reset();
+ assert(!fallthrough_called);
+ assert(!realtime_called);
+ //interspersed
+ midi_device_input(&test_device, 1, 0xB0, 0, 0);
+ midi_device_input(&test_device, 1, MIDI_CLOCK, 0, 0);
+ midi_device_input(&test_device, 1, 0, 0, 0);
+ midi_device_input(&test_device, 1, MIDI_START, 0, 0);
+ midi_device_input(&test_device, 1, 1, 0, 0);
+ midi_device_process(&test_device);
+ assert(fallthrough_called);
+ assert(realtime_called);
+
+ midi_register_cc_callback(&test_device, cc_callback);
+ assert(!cc_called);
+ midi_device_input(&test_device, 3, 0xB0, 0, 1);
+ midi_device_process(&test_device);
+ assert(cc_called);
+
+ reset();
+ assert(!cc_called);
+ assert(!realtime_called);
+ midi_device_input(&test_device, 1, 0xB0, 0, 0);
+ midi_device_input(&test_device, 1, MIDI_CLOCK, 0, 0);
+ midi_device_input(&test_device, 1, 0, 0, 0);
+ midi_device_input(&test_device, 1, MIDI_START, 0, 0);
+ midi_device_input(&test_device, 1, 1, 0, 0);
+ midi_device_process(&test_device);
+ assert(cc_called);
+ assert(realtime_called);
+
+ reset();
+ assert(!anything_called());
+ midi_device_input(&test_device, 1, 0xB0, 0, 0);
+ midi_device_input(&test_device, 1, 0, 0, 0);
+ midi_device_process(&test_device);
+ assert(!anything_called());
+
+ printf("\n\nTEST PASSED!\n\n");
+ return 0;
+}
diff --git a/bootloader/midi/test/dummy_device.h b/bootloader/midi/test/dummy_device.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/bootloader/midi/test/dummy_device.h
diff --git a/bootloader/midi/test/sysex_test.c b/bootloader/midi/test/sysex_test.c
new file mode 100644
index 0000000..73a1915
--- /dev/null
+++ b/bootloader/midi/test/sysex_test.c
@@ -0,0 +1,79 @@
+//midi for embedded chips,
+//Copyright 2010 Alex Norman
+//
+//This file is part of avr-midi.
+//
+//avr-midi is free software: you can redistribute it and/or modify
+//it under the terms of the GNU General Public License as published by
+//the Free Software Foundation, either version 3 of the License, or
+//(at your option) any later version.
+//
+//avr-midi is distributed in the hope that it will be useful,
+//but WITHOUT ANY WARRANTY; without even the implied warranty of
+//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+//GNU General Public License for more details.
+//
+//You should have received a copy of the GNU General Public License
+//along with avr-midi. If not, see <http://www.gnu.org/licenses/>.
+
+#include "sysex_tools.h"
+#include <stdlib.h>
+#include <math.h>
+#include <assert.h>
+#include <string.h>
+#include <stdio.h>
+
+#define SIZE 1028
+
+int main(int argc, char * argv[]) {
+ unsigned int i, j;
+ uint8_t orig[SIZE];
+ uint8_t unpacked[SIZE];
+ uint8_t * packed = malloc(sizeof(uint8_t) * sysex_bit_packed_length(SIZE));
+ uint8_t * packed2 = malloc(sizeof(uint8_t) * sysex_bit_packed_length(SIZE));
+
+ for(i = 0; i < SIZE; i++)
+ orig[i] = rand() & 0xFF;
+
+ for (i = 1; i < 512; i++) {
+ assert(i == sysex_bit_unpacked_length(sysex_bit_packed_length(i)));
+ }
+
+ //test byte packing
+ for (i = 1; i < SIZE; i++) {
+ uint16_t res_size0 = sysex_bit_pack(packed, orig, i);
+ uint16_t res_size1 = sysex_bit_packed_length(i);
+ //printf("packed %d == %d\n", res_size0, res_size1);
+ assert(res_size0 == res_size1);
+ //make sure that the top bit isn't set
+ for (j = 0; j < res_size0; j++)
+ assert( (packed[i] & 0x80) == 0);
+ //just in case, zero out unpacked..
+ memset(unpacked, SIZE, 0);
+ res_size1 = sysex_bit_unpack(unpacked, packed, res_size0);
+ assert(i == sysex_bit_unpacked_length(res_size0));
+ //printf("unpacked %d == %d\n", res_size1, i);
+ assert(res_size1 == i);
+ res_size0 = memcmp(orig, unpacked, i);
+ assert(0 == res_size0);
+ }
+
+ for (i = 0, j = 0; i < (SIZE - 7); i += 7, j +=8) {
+ //pack in segments
+ assert(8 == sysex_bit_pack(packed2 + j, orig + i, 7));
+ }
+
+ for (i = 0, j = 0; i < (SIZE - 7); i += 7, j +=8) {
+ //pack in segments
+ assert(7 == sysex_bit_unpack(unpacked + i, packed2 + j, 8));
+ }
+ //make sure the unpacked contents are the same length
+ assert(0 == memcmp(unpacked, orig, SIZE - 7));
+ //make sure that packing in 7 byte segments is the same as packing all at once
+ assert(0 == memcmp(packed2, packed, sysex_bit_packed_length(SIZE - 7)));
+
+ free(packed);
+
+ printf("\n%s passed!\n\n", argv[0]);
+ return 0;
+}