Skip to content

Commit b0d511a

Browse files
committed
updated obc test files
1 parent 7f0df8c commit b0d511a

File tree

8 files changed

+135
-6
lines changed

8 files changed

+135
-6
lines changed

assets/code/assert_utils.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include "assert_utils.h"
2+
#include <stdio.h>
3+
#include <string.h>
4+
5+
void assert_bytes_equal(const uint8_t *expected, const uint8_t *actual, uint8_t len, const char *msg) {
6+
for (uint8_t i = 0; i < len; i++) {
7+
if (expected[i] != actual[i]) {
8+
printf("[FAIL] %s - Mismatch at byte %d: expected %02X, got %02X\n", msg, i, expected[i], actual[i]);
9+
return;
10+
}
11+
}
12+
printf("[PASS] %s\n", msg);
13+
}
14+
15+
void assert_string_equals(const char *expected, const char *actual, const char *msg) {
16+
if (strcmp(expected, actual) != 0) {
17+
printf("[FAIL] %s - expected '%s', got '%s'\n", msg, expected, actual);
18+
} else {
19+
printf("[PASS] %s\n", msg);
20+
}
21+
}

assets/code/assert_utils.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#ifndef ASSERT_UTILS_H
2+
#define ASSERT_UTILS_H
3+
4+
#include <stdint.h>
5+
6+
void assert_bytes_equal(const uint8_t *expected, const uint8_t *actual, uint8_t len, const char *msg);
7+
void assert_string_equals(const char *expected, const char *actual, const char *msg);
8+
9+
#endif

assets/code/mock_uart.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include "mock_uart.h"
2+
#include <string.h>
3+
#include <stdio.h>
4+
5+
static uint8_t uart_buffer[UART_BUFFER_SIZE];
6+
static uint8_t uart_index = 0;
7+
8+
void uart_init(void) {
9+
memset(uart_buffer, 0, UART_BUFFER_SIZE);
10+
uart_index = 0;
11+
}
12+
13+
void uart_send(uint8_t *data, uint8_t len) {
14+
if (len + uart_index >= UART_BUFFER_SIZE) return;
15+
memcpy(&uart_buffer[uart_index], data, len);
16+
uart_index += len;
17+
printf("UART Send: ");
18+
for (uint8_t i = 0; i < len; i++) printf("%02X ", data[i]);
19+
printf("\n");
20+
}
21+
22+
uint8_t uart_receive(uint8_t *buffer, uint8_t max_len) {
23+
if (uart_index == 0) return 0;
24+
uint8_t len = uart_index < max_len ? uart_index : max_len;
25+
memcpy(buffer, uart_buffer, len);
26+
uart_index = 0;
27+
return len;
28+
}

assets/code/mock_uart.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef MOCK_UART_H
2+
#define MOCK_UART_H
3+
4+
#include <stdint.h>
5+
6+
#define UART_BUFFER_SIZE 256
7+
8+
void uart_init(void);
9+
void uart_send(uint8_t *data, uint8_t len);
10+
uint8_t uart_receive(uint8_t *buffer, uint8_t max_len);
11+
12+
#endif

assets/code/test_commands.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include "test_commands.h"
2+
#include "mock_uart.h"
3+
#include "assert_utils.h"
4+
#include <string.h>
5+
#include <stdint.h>
6+
7+
void test_command_cw_transmission(void) {
8+
uart_init();
9+
uint8_t command[] = {0xA0}; // Simulate CW command
10+
uart_send(command, sizeof(command));
11+
12+
uint8_t response[32] = {0};
13+
uart_receive(response, 32);
14+
15+
uint8_t expected[] = {'C','W','-','R','E','A','D','Y'};
16+
assert_bytes_equal(expected, response, sizeof(expected), "CW Transmission Command");
17+
}
18+
19+
void test_flash_write_and_read(void) {
20+
// Placeholder for flash mock
21+
printf("[INFO] Flash write/read test is not implemented.\n");
22+
}
23+
24+
void test_watchdog_reset(void) {
25+
// Placeholder for reset trigger test
26+
printf("[INFO] Watchdog reset test is not implemented.\n");
27+
}

assets/code/test_commands.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#ifndef TEST_COMMANDS_H
2+
#define TEST_COMMANDS_H
3+
4+
void test_command_cw_transmission(void);
5+
void test_flash_write_and_read(void);
6+
void test_watchdog_reset(void);
7+
8+
#endif

assets/code/test_obc_main.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <stdio.h>
2+
#include "mock_uart.h"
3+
#include "test_commands.h"
4+
#include "assert_utils.h"
5+
6+
int main(void) {
7+
printf("Starting OBC Software Simulation Tests...\n\n");
8+
9+
test_command_cw_transmission();
10+
test_flash_write_and_read();
11+
test_watchdog_reset();
12+
13+
printf("\nAll tests completed.\n");
14+
return 0;
15+
}

obc-members/test-file.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,21 @@ This file helps catch software logic issues before they affect the satellite har
3535

3636
| Component | Description |
3737
|------------------------|-----------------------------------------------------------------------------|
38-
| `test_obc_main.c` | Main test runner that initializes the OBC environment and simulates execution |
39-
| `mock_uart.c/h` | Simulated UART communication layer with buffers to emulate data exchange |
40-
| `mock_flash.c/h` | Emulated flash memory to verify write and read operations |
41-
| `test_commands.c/h` | Functions for creating and dispatching test commands |
42-
| `assert_utils.c/h` | Custom assert functions for validating results |
43-
| `test_data/test_cases.txt` | List of binary or ASCII commands for test input |
38+
| [`test_obc_main.c`](/assets/code/test_obc_main.c) | Main test runner that initializes the OBC environment and simulates execution |
39+
| [`mock_uart.c` ](/assets/code/mock_uart.c) | Simulated UART communication layer with buffers to emulate data exchange |
40+
| [`mock_uart.h` ](/assets/code/mock_uart.h) | Simulated UART communication layer with buffers to emulate data exchange |
41+
| [`mock_flash.c` ](/assets/code/mock_flash.c) | Emulated flash memory to verify write and read operations |
42+
| [`mock_flash.h` ](/assets/code/mock_flash.h) | Emulated flash memory to verify write and read operations |
43+
| [`test_commands.c` ](/assets/code/test_commands.c) | Functions for creating and dispatching test commands |
44+
| [`test_commands.h` ](/assets/code/test_commands.h) | Functions for creating and dispatching test commands |
45+
| [`assert_utils.c` ](/assets/code/assert_utils.c) | Custom assert functions for validating results |
46+
| [`assert_utils.h` ](/assets/code/assert_utils.h) | Custom assert functions for validating results |
47+
| `test_data/test_cases.txt`| List of binary or ASCII commands for test input |
48+
49+
## Download Test File
50+
51+
To access the test file used for MAIN PIC validation, click the links above.
52+
4453

4554
---
4655

0 commit comments

Comments
 (0)