Skip to content

Commit 0a18b32

Browse files
authored
Merge pull request #4 from loopj/test-action
Run target tests automatically
2 parents 87227eb + 10befc4 commit 0a18b32

File tree

4 files changed

+34
-10
lines changed

4 files changed

+34
-10
lines changed

.github/workflows/test.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Run Tests
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
pull_request:
7+
8+
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Install dependencies
16+
run: |
17+
sudo apt-get update
18+
sudo apt-get install -y cmake build-essential
19+
20+
- name: Build test suite
21+
run: cmake -Bbuild -DJOYBUS_BACKEND_LOOPBACK=1 && cmake --build build
22+
23+
- name: Run tests
24+
run: ctest --test-dir build --output-on-failure

src/backend/loopback/joybus.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,24 @@ static int joybus_loopback_disable(struct joybus *bus)
1919

2020
static void handle_command_response(const uint8_t *buffer, uint8_t result, void *user_data)
2121
{
22-
struct joybus *bus = (struct joybus *)user_data;
22+
if (response_buffer == NULL || result <= 0)
23+
return;
2324

24-
// Our loopback "transfer" is just to copy all the bytes
25+
// Copy the bytes provided by the target into the read buffer
2526
memcpy(response_buffer, buffer, result);
27+
response_length = result;
2628
}
2729

2830
static int joybus_loopback_transfer(struct joybus *bus, const uint8_t *write_buf, uint8_t write_len, uint8_t *read_buf,
2931
uint8_t read_len, joybus_transfer_cb_t callback, void *user_data)
3032
{
31-
// Save the buffer to write the response to
33+
// Save the buffer to write the response to, default to zero length
3234
response_buffer = read_buf;
35+
response_length = 0;
3336

3437
// Handle the command using the registered target
3538
for (int i = 1; i <= write_len; i++) {
36-
int rc = joybus_target_byte_received(bus->target, write_buf, i, handle_command_response, NULL);
39+
int rc = joybus_target_byte_received(bus->target, write_buf, i, handle_command_response, bus);
3740
if (rc == 0) {
3841
// No more bytes expected
3942
break;
@@ -45,7 +48,7 @@ static int joybus_loopback_transfer(struct joybus *bus, const uint8_t *write_buf
4548
}
4649

4750
// Call the transfer complete callback
48-
callback(bus, read_len, user_data);
51+
callback(bus, response_length, user_data);
4952

5053
return 0;
5154
}

src/target/gc_controller.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ void joybus_gc_controller_init(struct joybus_gc_controller *controller, uint16_t
345345
target->api = &gc_controller_api;
346346

347347
// Set the initial controller ID
348+
memset(controller->id, 0, sizeof(controller->id));
348349
joybus_id_set_type_flags(controller->id, type);
349350

350351
// Set the initial origin

test/target/test_wavebird.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,9 @@ void setUp(void)
2727
joybus_loopback_init(&bus);
2828
joybus_enable(&bus);
2929

30-
// Register a standard GameCube controller target
30+
// Register a WaveBird receiver controller target
3131
joybus_gc_controller_init(&controller, JOYBUS_WAVEBIRD_RECEIVER);
3232
joybus_target_register(&bus, JOYBUS_TARGET(&controller));
33-
34-
// Reset response capture
35-
response_len = -1;
36-
memset(response, 0, sizeof(response));
3733
}
3834

3935
void tearDown(void)

0 commit comments

Comments
 (0)