Skip to content

Commit

Permalink
Fixes issue of tests not rebuilding correctly after modification
Browse files Browse the repository at this point in the history
  • Loading branch information
rhargreaves committed Sep 8, 2024
1 parent 8a85ea9 commit 79149b8
Show file tree
Hide file tree
Showing 43 changed files with 742 additions and 380 deletions.
22 changes: 13 additions & 9 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,13 @@ LDFLAGS+=$(foreach MOCK,$(MD_MOCKS),-Wl,--wrap=$(MOCK))
SYSTEM_TEST_LDFLAGS=$(LDFLAGS)
UNIT_TEST_LDFLAGS=$(LDFLAGS) $(foreach MOCK,$(MOCKS),-Wl,--wrap=$(MOCK))

SRC=$(wildcard ../src/*.c)
SRC+=$(wildcard ../src/*/*.c)
SRC=$(wildcard ../src/*.c ../src/*/*.c)
SRC:=$(filter-out ../src/boot/rom_head.c,$(SRC))
SRC:=$(filter-out ../src/main.c,$(SRC))

COMMON_TEST_SRC=$(wildcard *.c)
UNIT_TEST_SRC+=$(wildcard unit/*.c)
SYSTEM_TEST_SRC+=$(wildcard system/*.c)
UNIT_TEST_SRC=$(wildcard unit/*.c)
SYSTEM_TEST_SRC=$(wildcard system/*.c)

SRC_OBJ=$(patsubst ../src/%.c,obj/%.o,$(SRC))
COMMON_TEST_OBJ=$(patsubst %.c,obj/%.o,$(COMMON_TEST_SRC))
Expand All @@ -228,6 +227,7 @@ UNIT_TESTS_TARGET=$(BIN_DIR)/unit_tests
SYSTEM_TESTS_TARGET=$(BIN_DIR)/system_tests

all: unit system
.PHONY: all

unit: $(UNIT_TESTS_TARGET)
$(GDB) ./$(UNIT_TESTS_TARGET)
Expand All @@ -237,22 +237,24 @@ system: $(SYSTEM_TESTS_TARGET)
$(GDB) ./$(SYSTEM_TESTS_TARGET)
.PHONY: system

$(SRC_OBJ): | $(OBJ_DIR) $(CMOCKA_DIR)

$(OBJ_DIR):
mkdir -p $(dir $@)

$(OBJ_DIR)/%.o: %.c
mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c $< -o $@
$(CC) $(CFLAGS) -MMD -c $< -o $@

$(OBJ_DIR)/%.o: %.c
mkdir -p $(dir $@)
$(CC) $(CFLAGS) -MMD -c $< -o $@

$(UNIT_TESTS_TARGET): $(SRC_OBJ) $(UNIT_TEST_OBJ) $(COMMON_TEST_OBJ)
mkdir -p $(dir $@)
$(CC) -o $@ $^ $(UNIT_TEST_LDFLAGS)
$(CC) -MMD -o $@ $^ $(UNIT_TEST_LDFLAGS)

$(SYSTEM_TESTS_TARGET): $(SRC_OBJ) $(SYSTEM_TEST_OBJ) $(COMMON_TEST_OBJ)
mkdir -p $(dir $@)
$(CC) -o $@ $^ $(SYSTEM_TEST_LDFLAGS)
$(CC) -MMD -o $@ $^ $(SYSTEM_TEST_LDFLAGS)

$(CMOCKA_DIR):
mkdir -p $@
Expand All @@ -262,6 +264,8 @@ $(CMOCKA_DIR):

clean-target:
rm -rf $(UNIT_TESTS_TARGET) $(SYSTEM_TESTS_TARGET) $(OBJ_DIR)
.PHONY: clean-target

clean: clean-target
rm -rf $(CMOCKA_DIR)
.PHONY: clean
2 changes: 1 addition & 1 deletion tests/system/main.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "cmocka_inc.h"
#include "test_e2e.c"
#include "test_e2e.h"

#define e2e_test(test) cmocka_unit_test_setup(test, test_e2e_setup)

Expand Down
45 changes: 22 additions & 23 deletions tests/system/test_e2e.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "cmocka_inc.h"
#include "test_e2e.h"
#include "asserts.h"
#include "comm/comm.h"
#include "envelopes.h"
Expand Down Expand Up @@ -30,7 +30,7 @@ static const u8 TEST_MIDI_CHANNEL_11 = 10;
static const u8 TEST_VOLUME_MAX = 127;
static const u8 TEST_VELOCITY_MAX = 127;

static int test_e2e_setup(void** state)
int test_e2e_setup(void** state)
{
wraps_disable_checks();
scheduler_init();
Expand All @@ -42,7 +42,7 @@ static int test_e2e_setup(void** state)
return 0;
}

static void test_midi_note_on_event_sent_to_ym2612(void** state)
void test_midi_note_on_event_sent_to_ym2612(void** state)
{
stub_everdrive_as_present();
stub_usb_receive_note_on(TEST_MIDI_CHANNEL_1, 48, 127);
Expand All @@ -52,7 +52,7 @@ static void test_midi_note_on_event_sent_to_ym2612(void** state)
midi_receiver_read();
}

static void test_polyphonic_midi_sent_to_separate_ym2612_channels(void** state)
void test_polyphonic_midi_sent_to_separate_ym2612_channels(void** state)
{
stub_everdrive_as_present();
stub_usb_receive_cc(TEST_MIDI_CHANNEL_1, TEST_CC_POLYPHONIC, TEST_POLYPHONIC_ON);
Expand All @@ -72,7 +72,7 @@ static void test_polyphonic_midi_sent_to_separate_ym2612_channels(void** state)
midi_receiver_read();
}

static void test_psg_audible_if_note_on_event_triggered(void** state)
void test_psg_audible_if_note_on_event_triggered(void** state)
{
stub_everdrive_as_present();
stub_usb_receive_note_on(TEST_MIDI_CHANNEL_PSG_1, 60, TEST_VELOCITY_MAX);
Expand All @@ -83,15 +83,14 @@ static void test_psg_audible_if_note_on_event_triggered(void** state)
midi_receiver_read();
}

static void test_psg_not_audible_if_midi_channel_volume_set_and_there_is_no_note_on_event(
void** state)
void test_psg_not_audible_if_midi_channel_volume_set_and_there_is_no_note_on_event(void** state)
{
stub_everdrive_as_present();
stub_usb_receive_cc(TEST_MIDI_CHANNEL_PSG_1, TEST_CC_VOLUME, TEST_VOLUME_MAX);
midi_receiver_read();
}

static void test_general_midi_reset_sysex_stops_all_notes(void** state)
void test_general_midi_reset_sysex_stops_all_notes(void** state)
{
stub_everdrive_as_present();

Expand Down Expand Up @@ -137,7 +136,7 @@ static void remapChannel(u8 midiChannel, u8 deviceChannel)
}
}

static void test_remap_midi_channel_1_to_psg_channel_1()
void test_remap_midi_channel_1_to_psg_channel_1()
{
stub_everdrive_as_present();

Expand All @@ -159,7 +158,7 @@ static void test_remap_midi_channel_1_to_psg_channel_1()
midi_receiver_read();
}

static void test_set_device_for_midi_channel_1_to_psg()
void test_set_device_for_midi_channel_1_to_psg()
{
stub_everdrive_as_present();
stub_usb_receive_cc(TEST_MIDI_CHANNEL_1, TEST_CC_POLYPHONIC, TEST_POLYPHONIC_ON);
Expand All @@ -176,7 +175,7 @@ static void test_set_device_for_midi_channel_1_to_psg()
midi_receiver_read();
}

static void test_pong_received_after_ping_sent()
void test_pong_received_after_ping_sent()
{
const u8 sysExPingSequence[] = { SYSEX_START, SYSEX_MANU_EXTENDED, SYSEX_MANU_REGION,
SYSEX_MANU_ID, SYSEX_COMMAND_PING, SYSEX_END };
Expand All @@ -197,7 +196,7 @@ static void test_pong_received_after_ping_sent()
midi_receiver_read();
}

static void test_loads_psg_envelope()
void test_loads_psg_envelope()
{
const u8 sysExPingSequence[] = { SYSEX_START, SYSEX_MANU_EXTENDED, SYSEX_MANU_REGION,
SYSEX_MANU_ID, SYSEX_COMMAND_LOAD_PSG_ENVELOPE, 0x06, 0x06, SYSEX_END };
Expand All @@ -216,15 +215,15 @@ static void test_loads_psg_envelope()
midi_receiver_read();
}

static void test_enables_ch3_special_mode(void** state)
void test_enables_ch3_special_mode(void** state)
{
stub_everdrive_as_present();
stub_usb_receive_cc(TEST_MIDI_CHANNEL_1, TEST_CC_SPECIAL_MODE, TEST_SPECIAL_MODE_ON);
expect_ym2612_write_reg(0, 0x27, 0x40);
midi_receiver_read();
}

static void test_sets_separate_ch3_operator_frequencies(void** state)
void test_sets_separate_ch3_operator_frequencies(void** state)
{
stub_everdrive_as_present();
stub_usb_receive_cc(TEST_MIDI_CHANNEL_1, TEST_CC_SPECIAL_MODE, TEST_SPECIAL_MODE_ON);
Expand All @@ -248,7 +247,7 @@ static void test_sets_separate_ch3_operator_frequencies(void** state)
}
}

static void test_pitch_bends_ch3_special_mode_operators(void** state)
void test_pitch_bends_ch3_special_mode_operators(void** state)
{
stub_everdrive_as_present();
stub_usb_receive_cc(TEST_MIDI_CHANNEL_1, TEST_CC_SPECIAL_MODE, TEST_SPECIAL_MODE_ON);
Expand All @@ -271,7 +270,7 @@ static void test_pitch_bends_ch3_special_mode_operators(void** state)
midi_receiver_read();
}

static void test_write_directly_to_ym2612_regs_via_sysex(void** state)
void test_write_directly_to_ym2612_regs_via_sysex(void** state)
{
stub_everdrive_as_present();

Expand All @@ -283,7 +282,7 @@ static void test_write_directly_to_ym2612_regs_via_sysex(void** state)
midi_receiver_read();
}

static void test_plays_pcm_sample(void** state)
void test_plays_pcm_sample(void** state)
{
stub_everdrive_as_present();
stub_usb_receive_cc(TEST_MIDI_CHANNEL_1, TEST_CC_ENABLE_DAC, 127);
Expand All @@ -299,7 +298,7 @@ static void test_plays_pcm_sample(void** state)
midi_receiver_read();
}

static void test_midi_last_note_played_priority_respected_on_fm(void** state)
void test_midi_last_note_played_priority_respected_on_fm(void** state)
{
stub_everdrive_as_present();
stub_usb_receive_note_on(TEST_MIDI_CHANNEL_1, 48, 127);
Expand All @@ -321,7 +320,7 @@ static void test_midi_last_note_played_priority_respected_on_fm(void** state)
midi_receiver_read();
}

static void test_midi_last_note_played_remembers_velocity_on_fm(void** state)
void test_midi_last_note_played_remembers_velocity_on_fm(void** state)
{
stub_everdrive_as_present();
stub_usb_receive_note_on(TEST_MIDI_CHANNEL_1, 48, 100);
Expand All @@ -347,7 +346,7 @@ static void test_midi_last_note_played_remembers_velocity_on_fm(void** state)
midi_receiver_read();
}

static void test_midi_last_note_played_cleared_when_released_on_fm(void** state)
void test_midi_last_note_played_cleared_when_released_on_fm(void** state)
{
stub_everdrive_as_present();
stub_usb_receive_note_on(TEST_MIDI_CHANNEL_1, 48, 127);
Expand All @@ -370,7 +369,7 @@ static void test_midi_last_note_played_cleared_when_released_on_fm(void** state)
midi_receiver_read();
}

static void test_midi_changing_program_retains_pan(void** state)
void test_midi_changing_program_retains_pan(void** state)
{
stub_everdrive_as_present();

Expand Down Expand Up @@ -414,7 +413,7 @@ static void test_midi_changing_program_retains_pan(void** state)
midi_receiver_read();
}

static void test_midi_changing_program_retains_volume(void** state)
void test_midi_changing_program_retains_volume(void** state)
{
stub_everdrive_as_present();

Expand Down Expand Up @@ -461,7 +460,7 @@ static void test_midi_changing_program_retains_volume(void** state)
midi_receiver_read();
}

static void test_midi_portamento_glides_note(void** state)
void test_midi_portamento_glides_note(void** state)
{
stub_everdrive_as_present();

Expand Down
23 changes: 23 additions & 0 deletions tests/system/test_e2e.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "cmocka_inc.h"

int test_e2e_setup(void** state);
void test_midi_note_on_event_sent_to_ym2612(void** state);
void test_polyphonic_midi_sent_to_separate_ym2612_channels(void** state);
void test_psg_audible_if_note_on_event_triggered(void** state);
void test_psg_not_audible_if_midi_channel_volume_set_and_there_is_no_note_on_event(void** state);
void test_general_midi_reset_sysex_stops_all_notes(void** state);
void test_remap_midi_channel_1_to_psg_channel_1();
void test_set_device_for_midi_channel_1_to_psg();
void test_pong_received_after_ping_sent();
void test_loads_psg_envelope();
void test_enables_ch3_special_mode(void** state);
void test_sets_separate_ch3_operator_frequencies(void** state);
void test_write_directly_to_ym2612_regs_via_sysex(void** state);
void test_plays_pcm_sample(void** state);
void test_midi_last_note_played_priority_respected_on_fm(void** state);
void test_midi_last_note_played_remembers_velocity_on_fm(void** state);
void test_midi_last_note_played_cleared_when_released_on_fm(void** state);
void test_midi_changing_program_retains_pan(void** state);
void test_midi_changing_program_retains_volume(void** state);
void test_midi_portamento_glides_note(void** state);
void test_pitch_bends_ch3_special_mode_operators(void** state);
38 changes: 19 additions & 19 deletions tests/unit/main.c
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
#include "cmocka_inc.h"
#include "test_applemidi.c"
#include "test_comm.c"
#include "test_comm_megawifi.c"
#include "test_comm_demo.c"
#include "test_log.c"
#include "test_applemidi.h"
#include "test_buffer.h"
#include "test_comm.h"
#include "test_comm_megawifi.h"
#include "test_comm_demo.h"
#include "test_log.h"
#include "test_midi.h"
#include "test_midi_dynamic.c"
#include "test_midi_fm.c"
#include "test_midi_polyphony.c"
#include "test_midi_psg.c"
#include "test_midi_receiver.c"
#include "test_midi_sysex.c"
#include "test_midi_dac.c"
#include "test_scheduler.c"
#include "test_synth.c"
#include "test_buffer.c"
#include "test_note_priority.c"
#include "test_midi_portamento.c"
#include "test_pitchcents.c"
#include "test_midi_finetune.c"
#include "test_midi_dac.h"
#include "test_midi_dynamic.h"
#include "test_midi_finetune.h"
#include "test_midi_fm.h"
#include "test_midi_polyphony.h"
#include "test_midi_portamento.h"
#include "test_midi_psg.h"
#include "test_midi_receiver.h"
#include "test_midi_sysex.h"
#include "test_scheduler.h"
#include "test_synth.h"
#include "test_note_priority.h"
#include "test_pitchcents.h"

#define midi_test(test) cmocka_unit_test_setup(test, test_midi_setup)
#define midi_pcm_test(test) cmocka_unit_test_setup(test, test_midi_setup)
Expand Down
Loading

0 comments on commit 79149b8

Please sign in to comment.