mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-19 05:39:17 +02:00
Issue 522 - Add unit test framework for C runtime (#545)
* WIP - C unit testing stubs * Get test-lib to compile and run * Add test-lib to CI * Use cflags for test-lib * Build runtime library * Fix typo * Break into separate CI tasks * Cleanup * Add example tests for non-CPS * Include -g option for test-lib * Add CI to build C runtime Can expand into scheme at some point, this is a first step. * Use latest upload workflow
This commit is contained in:
parent
645683937f
commit
45686f6c86
5 changed files with 109 additions and 1 deletions
|
@ -21,7 +21,7 @@ jobs:
|
||||||
|
|
||||||
- name: upload deb
|
- name: upload deb
|
||||||
if: matrix.arch == '64'
|
if: matrix.arch == '64'
|
||||||
uses: actions/upload-artifact@v1
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: cyclone-scheme docs
|
name: cyclone-scheme docs
|
||||||
path: html.tar.bz2
|
path: html.tar.bz2
|
27
.github/workflows/c-runtime-unit-tests.yml
vendored
Normal file
27
.github/workflows/c-runtime-unit-tests.yml
vendored
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
name: C Runtime Unit Tests
|
||||||
|
|
||||||
|
#on: [create]
|
||||||
|
on: [push]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
arch: [64]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
# Install dependencies
|
||||||
|
- name: Install libck
|
||||||
|
run: sudo apt-get install libck-dev
|
||||||
|
#- name: Install Cyclone
|
||||||
|
# run: |
|
||||||
|
# wget https://github.com/cyclone-scheme/binary-releases/raw/master/ubuntu-18.04-lts/cyclone-scheme_0.30.0_amd64.deb
|
||||||
|
# sudo apt install ./cyclone-scheme_0.30.0_amd64.deb
|
||||||
|
- uses: actions/checkout@v1
|
||||||
|
|
||||||
|
# Execute runtime library unit tests
|
||||||
|
- name: make test-lib
|
||||||
|
run: make libcyclone.a && make test-lib && ./test-lib
|
26
.github/workflows/ci.yml
vendored
Normal file
26
.github/workflows/ci.yml
vendored
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
name: Ubuntu Linux Build
|
||||||
|
|
||||||
|
on: [push]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
arch: [32, 64]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v1
|
||||||
|
- name: Install ck
|
||||||
|
run: sudo apt-get install libck-dev
|
||||||
|
- name: make runtime
|
||||||
|
run: make libcyclone.a
|
||||||
|
# - name: make
|
||||||
|
# run: make
|
||||||
|
# - name: make install
|
||||||
|
# run: sudo make install
|
||||||
|
# - name: make test
|
||||||
|
# run: make test
|
||||||
|
|
4
Makefile
4
Makefile
|
@ -342,3 +342,7 @@ install-bin : cyclone icyc
|
||||||
$(MKDIR) $(DESTDIR)$(BINDIR)
|
$(MKDIR) $(DESTDIR)$(BINDIR)
|
||||||
$(INSTALL) -m0755 cyclone $(DESTDIR)$(BINDIR)/
|
$(INSTALL) -m0755 cyclone $(DESTDIR)$(BINDIR)/
|
||||||
$(INSTALL) -m0755 icyc $(DESTDIR)$(BINDIR)/
|
$(INSTALL) -m0755 icyc $(DESTDIR)$(BINDIR)/
|
||||||
|
|
||||||
|
# TODO: is this linking in local lcyclone or the system one????
|
||||||
|
test-lib: test-lib.c
|
||||||
|
$(CCOMP) -g test-lib.c -o test-lib -L . $(LIBS)
|
||||||
|
|
51
test-lib.c
Normal file
51
test-lib.c
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include "include/cyclone/types.h"
|
||||||
|
#include "include/cyclone/runtime.h"
|
||||||
|
#include "include/cyclone/runtime-main.h"
|
||||||
|
|
||||||
|
/* Future considerations:
|
||||||
|
int main(int argc, char **argv, char **envp)
|
||||||
|
{gc_thread_data *thd;
|
||||||
|
long stack_size = global_stack_size = STACK_SIZE;
|
||||||
|
long heap_size = global_heap_size = HEAP_SIZE;
|
||||||
|
init_polyfills();
|
||||||
|
mclosure0(clos_halt,&Cyc_halt); // Halt if final closure is reached
|
||||||
|
mclosure0(entry_pt,&c_entry_pt); // First function to execute
|
||||||
|
_cyc_argc = argc;
|
||||||
|
_cyc_argv = argv;
|
||||||
|
set_env_variables(envp);
|
||||||
|
gc_initialize();
|
||||||
|
thd = malloc(sizeof(gc_thread_data));
|
||||||
|
gc_thread_data_init(thd, 0, (char *) &stack_size, stack_size);
|
||||||
|
thd->gc_cont = &entry_pt;
|
||||||
|
thd->gc_args[0] = &clos_halt;
|
||||||
|
thd->gc_num_args = 1;
|
||||||
|
thd->thread_id = pthread_self();
|
||||||
|
gc_add_mutator(thd);
|
||||||
|
Cyc_heap_init(heap_size);
|
||||||
|
thd->thread_state = CYC_THREAD_STATE_RUNNABLE;
|
||||||
|
Cyc_start_trampoline(thd);
|
||||||
|
return 0;}
|
||||||
|
*/
|
||||||
|
|
||||||
|
void test_exact() {
|
||||||
|
common_type ptr;
|
||||||
|
make_double(d, 42.5);
|
||||||
|
assert(obj_int2obj(42) == Cyc_exact_no_cps(NULL, &ptr, obj_int2obj(42)));
|
||||||
|
object result = Cyc_exact_no_cps(NULL, &ptr, &d);
|
||||||
|
assert( result == obj_int2obj(43));
|
||||||
|
|
||||||
|
// TODO: unit tests for below as examples:
|
||||||
|
//void Cyc_exact(void *data, object cont, object z)
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
assert(boolean_t == boolean_t);
|
||||||
|
assert(boolean_t != boolean_f);
|
||||||
|
|
||||||
|
test_exact();
|
||||||
|
|
||||||
|
printf("All tests passed successfully!\n");
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue