Skip to content

Commit

Permalink
testing for libgap saving/loading workspaces
Browse files Browse the repository at this point in the history
Currently loading does not work due to GAP issue gap-system#2832
  • Loading branch information
dimpase authored and fingolfin committed Nov 1, 2018
1 parent 3336f95 commit cb3d904
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 61 deletions.
13 changes: 10 additions & 3 deletions Makefile.rules
Original file line number Diff line number Diff line change
Expand Up @@ -990,11 +990,18 @@ testbugfix: all
ReadGapRoot( "tst/testbugfix.g" );' | $(TESTGAP) | \
tee `date -u +dev/log/testbugfix2_%Y-%m-%d-%H-%M` )

testlibgap: libgap.la obj/tst/testlibgap/basic.lo
$(QUIET_LINK)$(LINK) $(GAP_LDFLAGS) obj/tst/testlibgap/basic.lo libgap.la -o test-libgap
testlibgapws: libgap.la obj/tst/testlibgap/wscreate.lo obj/tst/testlibgap/wsload.lo obj/tst/testlibgap/common.lo
$(LINK) $(GAP_LDFLAGS) obj/tst/testlibgap/wscreate.lo obj/tst/testlibgap/common.lo libgap.la -o test-libgapwscreate
$(LINK) $(GAP_LDFLAGS) obj/tst/testlibgap/wsload.lo obj/tst/testlibgap/common.lo libgap.la -o test-libgapwsload
./test-libgapwscreate -A -l $(top_srcdir) -m 32m -q -T --nointeract
./test-libgapwsload -A -l $(top_srcdir) -m 32m -q -T --nointeract -L /tmp/libgap.ws

testlibgap: libgap.la obj/tst/testlibgap/basic.lo obj/tst/testlibgap/common.lo
$(QUIET_LINK)$(LINK) $(GAP_LDFLAGS) obj/tst/testlibgap/basic.lo obj/tst/testlibgap/common.lo libgap.la -o test-libgap
./test-libgap -A -l $(top_srcdir) -m 32m -q -T --nointeract > basic.out
diff $(top_srcdir)/tst/testlibgap/basic.expect basic.out
.PHONY: testlibgap

.PHONY: testlibgap testlibgapws

coverage:
gcov -o . $(SOURCES)
Expand Down
59 changes: 1 addition & 58 deletions tst/testlibgap/basic.c
Original file line number Diff line number Diff line change
@@ -1,64 +1,7 @@
/*
* Small program to test libgap linkability and basic working
*/
#include <stdio.h>
#include <unistd.h>
#include <compiled.h>
#include <libgap-api.h>
extern char ** environ;

UInt GAP_List_Length(Obj list)
{
return LEN_LIST(list);
}

Obj GAP_List_AtPosition(Obj list, Int pos)
{
return ELM_LIST(list, pos);
}

UInt GAP_String_Length(Obj string)
{
return GET_LEN_STRING(string);
}

Int GAP_String_GetCString(Obj string, Char * buffer, UInt n)
{
UInt len;

if (IS_STRING(string)) {
if (!IS_STRING_REP(string))
string = CopyToStringRep(string);
len = GET_LEN_STRING(string) + 1;
if (len >= n)
len = n - 1;
// Have to use mempcy because GAP strings can contain
// \0.
memcpy(buffer, CSTR_STRING(string), len);
if (len == n - 1)
buffer[n] = '\0';
return 1;
}
return 0;
}

void test_eval(const char * cmd)
{
Obj res, ires;
Int rc, i;
Char buffer[4096];
printf("gap> %s\n", cmd);
res = GAP_EvalString(cmd);
rc = GAP_List_Length(res);
for (i = 1; i <= rc; i++) {
ires = GAP_List_AtPosition(res, i);
if (GAP_List_AtPosition(ires, 1) == True) {
GAP_String_GetCString(GAP_List_AtPosition(ires, 5), buffer,
sizeof(buffer));
printf("%s\n", buffer);
}
}
}
#include "common.h"
int main(int argc, char ** argv)
{
printf("# Initializing GAP...\n");
Expand Down
57 changes: 57 additions & 0 deletions tst/testlibgap/common.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Small program to test libgap linkability and basic working
*/
#include "common.h"

UInt GAP_List_Length(Obj list)
{
return LEN_LIST(list);
}

Obj GAP_List_AtPosition(Obj list, Int pos)
{
return ELM_LIST(list, pos);
}

UInt GAP_String_Length(Obj string)
{
return GET_LEN_STRING(string);
}

Int GAP_String_GetCString(Obj string, Char * buffer, UInt n)
{
UInt len;

if (IS_STRING(string)) {
if (!IS_STRING_REP(string))
string = CopyToStringRep(string);
len = GET_LEN_STRING(string) + 1;
if (len >= n)
len = n - 1;
// Have to use mempcy because GAP strings can contain
// \0.
memcpy(buffer, CSTR_STRING(string), len);
if (len == n - 1)
buffer[n] = '\0';
return 1;
}
return 0;
}

void test_eval(const char * cmd)
{
Obj res, ires;
Int rc, i;
Char buffer[4096];
printf("gap> %s\n", cmd);
res = GAP_EvalString(cmd);
rc = GAP_List_Length(res);
for (i = 1; i <= rc; i++) {
ires = GAP_List_AtPosition(res, i);
if (GAP_List_AtPosition(ires, 1) == True) {
GAP_String_GetCString(GAP_List_AtPosition(ires, 5), buffer,
sizeof(buffer));
printf("%s\n", buffer);
}
}
}
11 changes: 11 additions & 0 deletions tst/testlibgap/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <stdio.h>
#include <unistd.h>
#include <compiled.h>
#include <libgap-api.h>
extern char ** environ;

UInt GAP_List_Length(Obj list);
Obj GAP_List_AtPosition(Obj list, Int pos);
UInt GAP_String_Length(Obj string);
Int GAP_String_GetCString(Obj string, Char * buffer, UInt n);
void test_eval(const char * cmd);
21 changes: 21 additions & 0 deletions tst/testlibgap/wscreate.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Small program to test libgap linkability and basic working
*/
#include "common.h"
int main(int argc, char ** argv)
{
char ws[80] = "SaveWorkspace(\"/tmp/libgap.ws\");\n";
printf("# Initializing GAP...\n");
GAP_Initialize(argc, argv, environ, 0L, 0L);
CollectBags(0, 1); // full GC
test_eval("1+2+3;");
test_eval("g:=FreeGroup(2);");
test_eval("a:=g.1;");
test_eval("b:=g.2;");
test_eval("lis:=[a^2, a^2, b*a];");
test_eval("h:=g/lis;");
test_eval("c:=h.1;");
test_eval(ws);
printf("# done\n");
return 0;
}
17 changes: 17 additions & 0 deletions tst/testlibgap/wsload.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Small program to test libgap ability to save workspaces
*/
#include "common.h"
int main(int argc, char ** argv)
{
printf("# Initializing GAP...\n");
GAP_Initialize(argc, argv, environ, 0L, 0L);
printf("# looking at saved stuff...\n");
test_eval("g;");
test_eval("a;");
test_eval("b;");
test_eval("[a^2, a^2, b*a];");
test_eval("Order(h);");
printf("# done\n");
return 0;
}

0 comments on commit cb3d904

Please sign in to comment.