added a small test case for gc
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
hyung-hwan 2024-04-23 00:39:01 +09:00
parent 27bf77b51e
commit 9271fae745
6 changed files with 54 additions and 17 deletions

View File

@ -13,7 +13,7 @@ LDFLAGS_COMMON=-L$(abs_builddir)/../lib -L$(libdir)
## for more information. ## for more information.
LIBADD_COMMON = ../lib/libhawk.la $(LIBM) LIBADD_COMMON = ../lib/libhawk.la $(LIBM)
check_SCRIPTS = h-001.hawk h-002.hawk h-003.hawk h-009.hawk check_SCRIPTS = h-001.hawk h-002.hawk h-003.hawk h-004.hawk h-009.hawk
##noinst_SCRIPTS = $(check_SCRIPTS) ##noinst_SCRIPTS = $(check_SCRIPTS)
EXTRA_DIST = $(check_SCRIPTS) tap.inc \ EXTRA_DIST = $(check_SCRIPTS) tap.inc \
journal-toc.hawk journal-toc.in journal-toc.out journal-toc-html.out \ journal-toc.hawk journal-toc.in journal-toc.out journal-toc-html.out \

View File

@ -578,7 +578,7 @@ CPPFLAGS_COMMON = \
CFLAGS_COMMON = CFLAGS_COMMON =
LDFLAGS_COMMON = -L$(abs_builddir)/../lib -L$(libdir) LDFLAGS_COMMON = -L$(abs_builddir)/../lib -L$(libdir)
LIBADD_COMMON = ../lib/libhawk.la $(LIBM) LIBADD_COMMON = ../lib/libhawk.la $(LIBM)
check_SCRIPTS = h-001.hawk h-002.hawk h-003.hawk h-009.hawk check_SCRIPTS = h-001.hawk h-002.hawk h-003.hawk h-004.hawk h-009.hawk
EXTRA_DIST = $(check_SCRIPTS) tap.inc \ EXTRA_DIST = $(check_SCRIPTS) tap.inc \
journal-toc.hawk journal-toc.in journal-toc.out journal-toc-html.out \ journal-toc.hawk journal-toc.in journal-toc.out journal-toc-html.out \
bibtex-to-html.hawk bibtex-to-html.out bibtex-to-html.hawk bibtex-to-html.out

View File

@ -420,7 +420,7 @@ function do_cite(s, k,n,labels,t)
function do_line( n,name,s) function do_line( n,name,s)
{ {
s = protect_SGML_characters($0) s = protect_SGML_characters($0)
if (match(s,STRING_PATTERN)) # remember name from @String{name = "value"} if (match(s,STRING_PATTERN)) # remember name from @String{name = "value"}
{ {
name = substr(s,RSTART + STRING_OFFSET,RLENGTH - STRING_OFFSET) name = substr(s,RSTART + STRING_OFFSET,RLENGTH - STRING_OFFSET)
@ -520,7 +520,7 @@ function protect_SGML_characters(s)
gsub(/</,"\\&lt;",s) gsub(/</,"\\&lt;",s)
gsub(/>/,"\\&gt;",s) gsub(/>/,"\\&gt;",s)
## [24-May-2016] with the change from HTML 3.2 to 4.0, we can use &quot; again! ## [24-May-2016] with the change from HTML 3.2 to 4.0, we can use &quot; again!
## gsub(/\"/,"\\&#34;",s) # this was &quot; in earlier HTML ## gsub(/\"/,"\\&#34;",s) # this was &quot; in earlier HTML
# versions, including the HTML 3.2 # versions, including the HTML 3.2
# draft, but was stupidly eliminated in # draft, but was stupidly eliminated in

View File

@ -136,7 +136,7 @@ function main()
x = 20; x = 20;
y = 90; y = 90;
r = call_by_ref_1(x, y, z); r = call_by_ref_1(x, y, z);
tap_ensure (r, 1800, @SCRIPTNAME, @SCRIPTLINE); tap_ensure (r, 1800, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (x, 20, @SCRIPTNAME, @SCRIPTLINE); tap_ensure (x, 20, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (y, 90, @SCRIPTNAME, @SCRIPTLINE); tap_ensure (y, 90, @SCRIPTNAME, @SCRIPTLINE);
@ -179,7 +179,7 @@ function main()
{ {
@local a; @local a;
a[1] = hawk::array(); a[1] = hawk::array();
a[1][2]=20; a[1][2]=20;
tap_ensure (a[1][2], 20, @SCRIPTNAME, @SCRIPTLINE); tap_ensure (a[1][2], 20, @SCRIPTNAME, @SCRIPTLINE);
a[1][2]++; a[1][2]++;
tap_ensure (a[1][2], 21, @SCRIPTNAME, @SCRIPTLINE); tap_ensure (a[1][2], 21, @SCRIPTNAME, @SCRIPTLINE);
@ -217,22 +217,22 @@ function main()
{ {
@local a, i; @local a, i;
a = hawk::array(); a = hawk::array();
tap_ensure (length(a), 0, @SCRIPTNAME, @SCRIPTLINE); tap_ensure (length(a), 0, @SCRIPTNAME, @SCRIPTLINE);
for (i = 0; i < 10; i++) a[i*i]=i; for (i = 0; i < 10; i++) a[i*i]=i;
tap_ensure (length(a), 10, @SCRIPTNAME, @SCRIPTLINE); tap_ensure (length(a), 10, @SCRIPTNAME, @SCRIPTLINE);
delete a[0]; delete a[0];
tap_ensure (length(a), 9, @SCRIPTNAME, @SCRIPTLINE); tap_ensure (length(a), 9, @SCRIPTNAME, @SCRIPTLINE);
delete a[81]; delete a[81];
tap_ensure (length(a), 8, @SCRIPTNAME, @SCRIPTLINE); tap_ensure (length(a), 8, @SCRIPTNAME, @SCRIPTLINE);
delete a[36]; delete a[36];
tap_ensure (length(a), 7, @SCRIPTNAME, @SCRIPTLINE); tap_ensure (length(a), 7, @SCRIPTNAME, @SCRIPTLINE);
for (i = 0; i < 10; i++) delete a[i*i]; for (i = 0; i < 10; i++) delete a[i*i];
tap_ensure (length(a), 0, @SCRIPTNAME, @SCRIPTLINE); tap_ensure (length(a), 0, @SCRIPTNAME, @SCRIPTLINE);
delete a; delete a;

View File

@ -6,7 +6,7 @@
function are_files_identical(a, b) function are_files_identical(a, b)
{ {
@local f1, f2, x, y, diff; @local f1, f2, x, y, diff;
f1 = sys::open(a, sys::O_RDONLY); f1 = sys::open(a, sys::O_RDONLY);
if (f1 <= -1) if (f1 <= -1)
{ {
@ -25,7 +25,7 @@ function are_files_identical(a, b)
diff = 0; diff = 0;
while (sys::read(f1, x, 1) > 0) while (sys::read(f1, x, 1) > 0)
{ {
if (sys::read(f2, y, 1) <= 0 || x !== y) if (sys::read(f2, y, 1) <= 0 || x !== y)
{ {
diff = 1; diff = 1;
break; break;
@ -58,12 +58,12 @@ function run_test (x, more_opts, in_name, set_out_name, out_name)
else else
{ {
cmd=sprintf("%s %s -f %s/%s.hawk --modlibdirs=%s %s > %s", ARGV[0], more_opts, TDIR, x, hawk::modlibdirs(), inf, outf); cmd=sprintf("%s %s -f %s/%s.hawk --modlibdirs=%s %s > %s", ARGV[0], more_opts, TDIR, x, hawk::modlibdirs(), inf, outf);
} }
##print cmd; ##print cmd;
system (cmd); system (cmd);
same = are_files_identical(expf, outf); same = are_files_identical(expf, outf);
if (same <= 0) if (same <= 0)
{ {
## don't delete the output file for review. ## don't delete the output file for review.
tap_fail (sprintf("%s[%d] %s - %s and %s differ", @SCRIPTNAME, @SCRIPTLINE, x, expf, outf)); tap_fail (sprintf("%s[%d] %s - %s and %s differ", @SCRIPTNAME, @SCRIPTLINE, x, expf, outf));

37
t/h-004.hawk Normal file
View File

@ -0,0 +1,37 @@
@pragma entry main
@pragma implicit off
@include "tap.inc";
function run_gc_test ()
{
@local i, a, b, ts, pr, cpr;
tap_ensure (hawk::GC_NUM_GENS, 3, @SCRIPTNAME, @SCRIPTLINE);
hawk::gc_set_threshold(0, 30);
ts = hawk::gc_get_threshold(0);
tap_ensure (ts, 30, @SCRIPTNAME, @SCRIPTLINE);
pr = hawk::gc_get_pressure(0);
for (i = 0; i < 50; i++)
{
a[1] = 999; ## there is only 1 allocation that's concerting GC in the current implementation
b = a;
b = @nil;
a = @nil;
cpr = hawk::gc_get_pressure(0);
if (pr + i + 1 <= ts)
tap_ensure (cpr, pr + i + 1, @SCRIPTNAME, @SCRIPTLINE);
else ## gc kicks in when the pressure reaches the threshold, the pressure drops...
tap_ensure (cpr, (pr + i + 1) - ts, @SCRIPTNAME, @SCRIPTLINE);
}
}
function main()
{
run_gc_test();
tap_end ();
}