test/stp: build the simulator against the firmware headers

test/stp/shim held hand-written copies of the headers the STP code
includes, and they had drifted: the uIP buffer was 600 bytes instead of
1556, struct machine had three fields, port_ingress_filter_get()
returned a plain uint8_t. The simulator now compiles rtl837x_stp.c and
rtl837x_stp_cli.c the way test/ compiles firmware sources, with the real
headers and sdcc_shim.h forced in, and with the same warnings, including
-Wno-pointer-sign for the string literals passed to cmd_compare(). It
stays on -std=c11: in gnu11 mode glibc defines LITTLE_ENDIAN, which
uip-conf.h names as the byte order, and HTONS() stops swapping. Its own
print_string() and cmd_compare() take the firmware's argument types.
This commit is contained in:
DrDoof authored and d00f committed 2026-10-27 22:11:24 +01:00
1 parent aff6ac0923
commit e19271fc44
8 files changed
+17 -106

No files matched your search

+15 -8
View File
@@ -1,7 +1,16 @@
CC ?= cc
CFLAGS = -std=c11 -Wall -Wextra -Wno-unknown-pragmas \
-D__xdata= -D__code= -D__banked= -D__reentrant= \
-Ishim -I../..
CC ?= cc
SRCROOT = ../..
CFLAGS = -std=c11 -g -O1 -Wall -Wextra -Werror -Wno-unused-parameter -Wno-unknown-pragmas \
-Wno-pointer-sign \
-DRTLP_HOST_TEST \
-fsanitize=address,undefined -fno-omit-frame-pointer \
-include ../sdcc_shim.h -I../stub -I$(SRCROOT) -I$(SRCROOT)/httpd -I$(SRCROOT)/uip
ifeq ($(findstring clang,$(shell $(CC) --version 2>/dev/null)),)
CFLAGS += -Wno-builtin-declaration-mismatch
endif
LDFLAGS = -fsanitize=address,undefined
SRCS = stp_sim.c $(SRCROOT)/rtl837x_stp.c $(SRCROOT)/rtl837x_stp_cli.c
all: build/stp_sim
./build/stp_sim
@@ -9,11 +18,9 @@ all: build/stp_sim
verbose: build/stp_sim
./build/stp_sim -v
build/stp_sim: stp_sim.c ../../rtl837x_stp.c ../../rtl837x_stp_cli.c ../../rtl837x_stp.h shim/*.h
build/stp_sim: $(SRCS) $(SRCROOT)/rtl837x_stp.h
mkdir -p build
cp ../../rtl837x_stp.c build/stp_under_test.c
cp ../../rtl837x_stp_cli.c build/stp_cli_under_test.c
$(CC) $(CFLAGS) -o $@ stp_sim.c build/stp_under_test.c build/stp_cli_under_test.c
$(CC) $(CFLAGS) $(SRCS) -o $@ $(LDFLAGS)
clean:
rm -rf build
-12
View File
@@ -1,12 +0,0 @@
#ifndef _SHIM_MACHINE_H_
#define _SHIM_MACHINE_H_
#include <stdint.h>
#define MACHINE_MIN_PORT 0
#define MACHINE_MAX_PORT 8
#define MACHINE_PORT_VALID(p) \
((uint8_t)((p) - MACHINE_MIN_PORT) <= (MACHINE_MAX_PORT - MACHINE_MIN_PORT))
struct machine { uint8_t log_to_phys_port[9]; };
extern const struct machine machine;
struct machine_runtime { uint8_t isRTL8373; };
extern struct machine_runtime machine_detected;
#endif
-50
View File
@@ -1,50 +0,0 @@
#ifndef _SHIM_RTL837X_COMMON_H_
#define _SHIM_RTL837X_COMMON_H_
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
struct rtl_tag {
uint16_t tag;
uint8_t version;
uint8_t reason;
uint16_t flags;
uint16_t pmask; /* TX: port bitmask; RX: 4-bit port number */
};
struct vlan_tag {
uint16_t svlan;
uint16_t vlan;
};
#define RTL_FRAME_TAG_ID 0x8899
#define RTL_FRAME_TAG_VERSION 0x04
#define RTL_FRAME_DESC_SIZE 12
#define RTL_TAG_LEARN_DIS 0x0020
#define PMASK_9 0x1ff
#define PMASK_6 0x1f8
#define PMASK_CPU 0x200
#define CMD_BUF_SIZE 128
#define CPU_PORT 9
#define ERR_OK 0
#define ERR_INVALID_ARGUMENT 3
#define HTONS(n) ((uint16_t)((((uint16_t)(n)) << 8) | (((uint16_t)(n)) >> 8)))
extern bool stp_enabled;
void print_string(char *s);
void print_byte(uint8_t b);
void print_short(uint16_t v);
void print_long(uint32_t v);
void write_char(char c);
void itoa(uint8_t v);
void print_reg(uint16_t reg);
void reg_read_m(uint16_t addr);
void reg_write_m(uint16_t addr);
void tcpip_output(void);
#endif
-11
View File
@@ -1,11 +0,0 @@
#ifndef _SHIM_RTL837X_PORT_H_
#define _SHIM_RTL837X_PORT_H_
#include <stdint.h>
#define VLAN_TAGGED 1
int8_t vlan_get(uint16_t vlan);
uint16_t port_pvid_get(uint8_t port);
void port_l2mc_set(uint8_t mac_last, uint16_t vid, uint16_t pmask);
void port_l2_forget_port(uint8_t port);
uint16_t port_lag_members_get(uint8_t lag);
uint8_t port_ingress_filter_get(uint8_t port);
#endif
-9
View File
@@ -1,9 +0,0 @@
#ifndef _SHIM_RTL837X_REGS_H_
#define _SHIM_RTL837X_REGS_H_
#define RTL837X_MSTP_STATES 0x5310
#define RTL837X_REG_LINKS_STS 0x63E8
#define RTL837X_REG_LINKS 0x63f0
#define RTL837X_REG_LINKS_89 0x63f4
#endif
-6
View File
@@ -1,6 +0,0 @@
#ifndef _SHIM_RTL837X_SFR_H_
#define _SHIM_RTL837X_SFR_H_
extern unsigned char sfr_data[4];
#endif
-8
View File
@@ -1,8 +0,0 @@
#ifndef _SHIM_UIP_H_
#define _SHIM_UIP_H_
#include <stdint.h>
#define UIP_CONF_BUFFER_SIZE 600
struct uip_eth_addr { uint8_t addr[6]; };
extern uint16_t uip_len;
void tcpip_output(void);
#endif
+2 -2
View File
@@ -29,7 +29,7 @@ uint8_t err_status;
uint8_t atoi_results_u8;
static int verbose;
void print_string(char *s) { if (verbose) fputs(s, stdout); }
void print_string(const char *s) { if (verbose) fputs(s, stdout); }
void print_byte(uint8_t b) { if (verbose) printf("%02x", b); }
void print_short(uint16_t v) { if (verbose) printf("%04x", v); }
void print_long(uint32_t v) { if (verbose) printf("%08x", v); }
@@ -37,7 +37,7 @@ void write_char(char c) { if (verbose) putchar(c); }
void itoa(uint8_t v) { if (verbose) printf("%u", v); }
void print_reg(uint16_t reg) { (void)reg; }
uint8_t cmd_compare(uint8_t start, uint8_t *cmd)
uint8_t cmd_compare(uint8_t start, const uint8_t *cmd)
{
if (start >= cmd_words_len)
return 0;