-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
90c783f
commit 403fc10
Showing
5 changed files
with
210 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
name: Standalone Tests | ||
|
||
#trigger when these occur | ||
on: | ||
push: | ||
branches: | ||
- v2 | ||
pull_request: | ||
types: | ||
- opened | ||
- edited | ||
- reopened | ||
branches: | ||
- v2 | ||
workflow_dispatch: | ||
|
||
#These tests are more stand-alone than the others | ||
jobs: | ||
run-test-cases: | ||
continue-on-error: true | ||
strategy: | ||
matrix: | ||
platforms: | ||
- { os: ubuntu-latest, preinstall: sudo apt-get install gdb, gdb_enabled: true } | ||
- { os: windows-latest, preinstall: , gdb_enabled: true } | ||
- { os: macos-latest, preinstall: , gdb_enabled: false } | ||
commands: | ||
- { exec: make -C tests/standalone -k, gdb: false } | ||
- { exec: make -C tests/standalone gdb -k, gdb: true } | ||
|
||
runs-on: ${{ matrix.platforms.os }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Preinstall dependencies | ||
if: (matrix.commands.gdb == true && matrix.platforms.gdb_enabled == false) != true | ||
run: ${{ matrix.platforms.preinstall }} | ||
- name: run the tests | ||
if: (matrix.commands.gdb == true && matrix.platforms.gdb_enabled == false) != true | ||
run: ${{ matrix.commands.exec }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
set breakpoint pending on | ||
|
||
break strlen | ||
|
||
command 1 | ||
bt | ||
continue | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#compiler settings | ||
CC=gcc | ||
CFLAGS+=-std=c17 -g -Wall -Werror -Wno-unused-parameter -Wno-unused-function -Wno-unused-variable -Wformat=2 | ||
LIBS+=-lm | ||
LDFLAGS+= | ||
|
||
ifeq ($(shell uname),Linux) | ||
LDFLAGS=-Wl,--gc-sections | ||
else ifeq ($(OS),Windows_NT) | ||
LDFLAGS=-Wl,--gc-sections | ||
else ifeq ($(shell uname),Darwin) | ||
LDFLAGS=-Wl,-dead_strip | ||
else | ||
@echo "LDFLAGS set failed - what platform is this?" | ||
endif | ||
|
||
#directories | ||
TEST_SRCDIR= | ||
|
||
TEST_OUTDIR=out/ | ||
TEST_OBJDIR=obj/ | ||
|
||
#file names | ||
TEST_SRCFILES=$(wildcard $(TEST_SRCDIR)*.c) | ||
|
||
#kick off | ||
all: $(TEST_OBJDIR) $(TEST_OUTDIR) build run | ||
|
||
gdb: $(TEST_OBJDIR) $(TEST_OUTDIR) build gdb-run | ||
|
||
#build | ||
build: $(TEST_OBJDIR)$(TEST_SRCFILES:.c=.o) | ||
|
||
.PRECIOUS: $(TEST_OBJDIR)%.o | ||
$(TEST_OBJDIR)%.o: $(TEST_SRCDIR)%.c | ||
$(CC) -c -o $@ $< $(CFLAGS) -fdata-sections -ffunction-sections | ||
|
||
|
||
.PRECIOUS: $(TEST_OUTDIR)%.exe | ||
$(TEST_OUTDIR)%.exe: $(TEST_OBJDIR)%.o | ||
$(CC) -o $@ $< $(CFLAGS) $(LIBS) $(LDFLAGS) | ||
|
||
#run | ||
run: $(addprefix $(TEST_OUTDIR),$(TEST_SRCFILES:.c=.exe-run)) | ||
|
||
$(TEST_OUTDIR)%.exe-run: $(TEST_OUTDIR)%.exe | ||
$< | ||
|
||
#gdb-run | ||
gdb-run: $(addprefix $(TEST_OUTDIR),$(TEST_SRCFILES:.c=.exe-gdb-run)) | ||
|
||
$(TEST_OUTDIR)%.exe-gdb-run: $(TEST_OUTDIR)%.exe | ||
gdb $< -ix gdb_init -ex=run --batch --return-child-result | ||
|
||
#util targets | ||
$(TEST_OUTDIR): | ||
mkdir $(TEST_OUTDIR) | ||
|
||
$(TEST_OBJDIR): | ||
mkdir $(TEST_OBJDIR) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#include <stdio.h> | ||
#include <string.h> | ||
|
||
int getFilePath(char* dest, const char* src) { | ||
//extract the directory from src, and store it in dest | ||
#if defined(_WIN32) || defined(_WIN64) | ||
char* p = strrchr(src, '\\'); | ||
#else | ||
char* p = strrchr(src, '/'); | ||
#endif | ||
|
||
int len = p != NULL ? p - src + 1 : 0; | ||
strncpy(dest, src, len); | ||
dest[len] = '\0'; | ||
|
||
return len; | ||
} | ||
|
||
int getFileName(char* dest, const char* src) { | ||
//extract the directory from src, and store it in dest | ||
#if defined(_WIN32) || defined(_WIN64) | ||
char* p = strrchr(src, '\\'); | ||
#else | ||
char* p = strrchr(src, '/'); | ||
#endif | ||
|
||
//if we're not at the end of the string, skip the slash | ||
if (*p != '\0') { | ||
p++; | ||
} | ||
|
||
int len = strlen(p); | ||
strncpy(dest, p, len); | ||
dest[len] = '\0'; | ||
|
||
return len; | ||
} | ||
|
||
#define APPEND(dest, src) \ | ||
strncpy((dest) + (strlen(dest)), (src), strlen((src)) + 1); | ||
|
||
#if defined(_WIN32) || defined(_WIN64) | ||
#define FLIPSLASH(str) for (int i = 0; str[i]; i++) str[i] = str[i] == '/' ? '\\' : str[i]; | ||
#else | ||
#define FLIPSLASH(str) for (int i = 0; str[i]; i++) str[i] = str[i] == '\\' ? '/' : str[i]; | ||
#endif | ||
|
||
int main() { | ||
//check the platform | ||
printf("Platform: "); | ||
#if defined(__linux__) | ||
printf("Linux"); | ||
#elif defined(_WIN64) | ||
printf("Win64"); | ||
#elif defined(_WIN32) | ||
printf("Win32"); | ||
#elif defined(__APPLE__) | ||
printf("macOS"); | ||
#else | ||
printf("Unknown"); | ||
#endif | ||
|
||
printf("\n"); | ||
|
||
//run each test | ||
{ | ||
char src[256] = "../folder/file.txt"; | ||
char dest[256]; | ||
FLIPSLASH(src); | ||
getFilePath(dest, src); | ||
printf("Path: %s\n", dest); | ||
} | ||
|
||
{ | ||
char src[256] = "../folder/file.txt"; | ||
char dest[256]; | ||
FLIPSLASH(src); | ||
getFileName(dest, src); | ||
printf("Name: %s\n", dest); | ||
} | ||
|
||
{ | ||
char src[256] = "../folder/file.txt"; | ||
char dest[256]; | ||
FLIPSLASH(src); | ||
getFilePath(dest, src); | ||
APPEND(dest, "target.txt"); | ||
FLIPSLASH(dest); | ||
printf("Target: %s\n", dest); | ||
} | ||
|
||
return 0; | ||
} |