+#include "complex.h"
#include "gwion_util.h"
#include "gwion_ast.h"
#include "oo.h"
#include "object.h"
#include "instr.h"
#include "import.h"
+#include "gwi.h"
+#include "gwion.h"
SFUN(coverage_int) { *(m_uint*)RETURN = 0; }
SFUN(coverage_float) { *(m_float*)RETURN = 0; }
CHECK_BB(gwi_func_ini(gwi, "Vec4", "w", coverage_vec4))
CHECK_BB(gwi_func_end(gwi, ae_flag_static))
- m_uint* i = (m_uint*)xmalloc(sizeof(m_uint));
- *i = 5;
+ ALLOC_PTR(gwi->gwion->mp, i, m_uint, 5);
CHECK_BB(gwi_item_ini(gwi,"int", "s_i"))
CHECK_BB(gwi_item_end(gwi, ae_flag_static, i))
- m_float* f = (m_float*)xmalloc(sizeof(m_float));
- *f = 2.1;
- CHECK_BB(gwi_item_ini(gwi,"float", "s_f"))
+
+ ALLOC_PTR(gwi->gwion->mp, f, m_float, 2.1);
+ CHECK_BB(gwi_item_ini(gwi,"int", "s_f"))
CHECK_BB(gwi_item_end(gwi, ae_flag_static, (void*)f))
- m_complex* c = (m_complex*)xmalloc(sizeof(m_complex));
- *c = 2.1;
+ const m_complex _c = 2.1 + 2.2*I;
+ ALLOC_PTR(gwi->gwion->mp, c, m_complex, _c);
CHECK_BB(gwi_item_ini(gwi,"complex", "s_c"))
CHECK_BB(gwi_item_end(gwi, ae_flag_static, (void*)c))
- m_vec3* v = (m_vec3*)xmalloc(sizeof(m_vec3));
- v->x = 2.1;
- v->y = 2.2;
- v->z = 2.3;
+ const m_vec3 _v = { 2.1, 2.2, 2.3 };
+ ALLOC_PTR(gwi->gwion->mp, v, m_vec3, _v);
CHECK_BB(gwi_item_ini(gwi,"Vec3", "s_v"))
CHECK_BB(gwi_item_end(gwi, ae_flag_static, (void*)v))
- m_vec4* w = (m_vec4*)xmalloc(sizeof(m_vec4));
- w->x = 2.1;
- w->y = 2.2;
- w->z = 2.3;
- w->w = 2.4;
+ const m_vec4 _w = { 2.1, 2.2, 2.3, 2.4 };
+ ALLOC_PTR(gwi->gwion->mp, w, m_vec4, _w);
CHECK_BB(gwi_item_ini(gwi,"Vec4", "s_w"))
CHECK_BB(gwi_item_end(gwi, ae_flag_static, (void*)w))
- m_uint* ci = (m_uint*)xmalloc(sizeof(m_uint));
- *ci = 5;
+ ALLOC_PTR(gwi->gwion->mp, ci, m_uint, 5);
CHECK_BB(gwi_item_ini(gwi,"int", "sc_i"))
CHECK_BB(gwi_item_end(gwi, ae_flag_static | ae_flag_const, ci))
- m_float* cf = (m_float*)xmalloc(sizeof(m_float));
- *cf = 2.1;
+
+ ALLOC_PTR(gwi->gwion->mp, cf, m_float, 2.1);
CHECK_BB(gwi_item_ini(gwi,"float", "sc_f"))
CHECK_BB(gwi_item_end(gwi, ae_flag_static | ae_flag_const, (void*)cf))
- m_complex* cc = (m_complex*)xmalloc(sizeof(m_complex));
- *cc = 2.1;
+ const m_complex _cc = 2.1 + 2.2*I;
+ ALLOC_PTR(gwi->gwion->mp, cc, m_complex, _cc);
CHECK_BB(gwi_item_ini(gwi,"complex", "sc_c"))
CHECK_BB(gwi_item_end(gwi, ae_flag_static | ae_flag_const, (void*)cc))
- m_vec3* cv = (m_vec3*)xmalloc(sizeof(m_vec3));
- cv->x = 2.1;
- cv->y = 2.2;
- cv->z = 2.3;
+ const m_vec3 _cv = { 2.1, 2.2, 2.3 };
+ ALLOC_PTR(gwi->gwion->mp, cv, m_vec3, _cv);
CHECK_BB(gwi_item_ini(gwi,"Vec3", "sc_v"))
CHECK_BB(gwi_item_end(gwi, ae_flag_static | ae_flag_const, (void*)cv))
- m_vec4* cw = (m_vec4*)xmalloc(sizeof(m_vec4));
- cw->x = 2.1;
- cw->y = 2.2;
- cw->z = 2.3;
- cw->w = 2.4;
+ const m_vec4 _cw = { 2.1, 2.2, 2.3, 2.4 };
+ ALLOC_PTR(gwi->gwion->mp, cw, m_vec4, _cw);
CHECK_BB(gwi_item_ini(gwi,"Vec4", "sc_w"))
CHECK_BB(gwi_item_end(gwi, ae_flag_static | ae_flag_const, (void*)cw))
--- /dev/null
+#!/bin/bash
+
+: "${PRG:=gwion}"
+: "${VALGRIND:=valgrind}"
+: "${GWION_TEST_DIR:=/tmp}"
+: "${GWION_TEST_PREFIX:=gwt_}"
+
+: "${ANSI_RED:=\033[31;1m}"
+: "${ANSI_GREEN:=\033[32;1m}"
+: "${ANSI_BLUE:=\033[34;1m}"
+: "${ANSI_RESET:=\033[0m}"
+: "${ANSI_CLEAR:=\033[0K}"
+: "${ANSI_BOLD:=\033[33;1m}"
+
+: "${DRIVER:=dummy}"
+
+: "${ASYNC:=4}"
+: "${async:=$ASYNC}"
+
+: "${SEVERITY:=11}"
+: "${severity:=$SEVERITY}"
+
+assert_returns() {
+ [ "$1" -eq 0 ] && return 0
+ [ "$1" -eq 139 ] && echo "segfault" > "$2"
+ return 1;
+}
+
+assert_contain() {
+ local contains
+ contains=$(grep '// \[contains\]' "$1" | cut -d "]" -f2)
+ contains=${contains:1}
+ [ -z "$contains" ] && return 0
+ grep "$contains" "$2.err.log" > /dev/null && return 0
+ echo "does not contain $contains" > "$2.log"
+ return 1
+}
+
+assert_exclude() {
+ local contains
+ contains=$(grep '// \[excludes\]' "$1" | cut -d "]" -f2)
+ contains=${contains:1}
+ [ -z "$contains" ] && return 0
+ grep "$contains" "$2.err.log" > /dev/null || return 0
+ echo "does contain $contains" > "$2.log"
+ return 1
+}
+
+assert_rw() {
+ grep 'Invalid \(read\|write\) of size' "$2.valgrind.log" > /dev/null || return 0
+ echo "invalid read/write" > "$2.log"
+ return 1
+}
+
+assert_free() {
+ grep 'Invalid free()' "$2.valgrind.log" > /dev/null || return 0
+ echo "invalid free" > "$2.log"
+ return 1
+}
+
+assert_initial() {
+ grep 'Conditional jump or move depends on uninitialised value(s)' "$2.valgrind.log" > /dev/null || return 0
+ echo "uninitialed value" > "$2.log"
+ return 1
+}
+
+assert_syscall() {
+ grep 'Syscall param .* uninitialised byte(s)' "$2.valgrind.log" > /dev/null || return 0
+ echo "uninitialed value in syscall" > "$2.log"
+ return 1
+}
+
+assert_mismatch() {
+ grep 'Mismatched free() / delete / delete \[\]' "$2.valgrind.log" > /dev/null || return 0
+ echo "mismatched free" > "$2.log"
+ return 1
+}
+
+assert_overlap() {
+ grep 'Source and destination overlap' "$2.valgrind.log" > /dev/null || return 0
+ echo "mem overlap" > "$2.log"
+ return 1
+}
+
+assert_fishy() {
+ grep "Argument 'size' of .* has a fishy (possibly negative) value:" "$2.valgrind.log" > /dev/null || return 0
+ echo "fishy alloc" > "$2.log"
+ return 1
+}
+
+assert_leak() {
+ grep "All heap blocks were freed -- no leaks are possible" "$2.valgrind.log" > /dev/null && return 0
+ #[ "$suppressions" -eq 0 ] && echo "mem leak" > "$2.log" && return 1
+ #[ -z "$suppressions" ] && echo "mem leak" > "$2.log" && return 1
+ heap=$(grep "in use at exit:" "$2.valgrind.log" | cut -d ":" -f2)
+ supp=$(grep "suppressed: .* bytes" "$2.valgrind.log" | cut -d ":" -f2)
+ #[ -z "$supp" ] && echo "mem leak" > "$2.log" && return 1
+ [ "$heap" = "$supp" ] && return 0
+ echo "mem leak" > "$2.log"
+ return 1
+}
+
+read_test() {
+ while read -r line
+ do
+ if [ "$line" = "#*" ]
+ then printf '\t%s\n' line >&2
+ else echo "$line"
+ fi
+ done < "$1"
+}
+
+success() {
+ local n log desc
+ n=$1
+ desc=$2
+ log=$3
+ if [ "$async" -eq 0 ]
+ then echo "ok $(printf "% 4i" "$n") $desc"
+ else echo "ok $(printf "% 4i" "$n") $desc" > "$log"
+ fi
+ return 0
+}
+
+fail() {
+ local n log desc
+ n=$1
+ desc=$2
+ log=$3
+ if [ "$async" -eq 0 ]
+ then
+ echo "not ok $(printf "% 4i" "$n") $desc"
+ echo "# $(cat "$log")"
+ else
+ local info
+ info=$(cat "$log")
+ echo "not ok $(printf "% 4i" "$n") $desc" > "$log"
+ echo "# $info" >> "$log"
+ echo "$desc $(cat "$4")" >> "test.log"
+ fi
+ return 1
+}
+
+do_skip() {
+ local n SKIP skip
+ SKIP=0
+ skip=$(grep '// \[skip\]' "$1")
+ [ "$skip" ] && SKIP=1
+ [ $SKIP = 0 ] && return 1
+ skip=$(echo "$skip" | cut -d ']' -f2 )
+ n=$(printf "% 4i" "$2")
+ if [ "$async" -eq 0 ]
+ then echo "ok $(printf "% 4i" "$n") $3 # Skip $skip"
+ else echo "ok $(printf "% 4i" "$n") $3 # Skip $skip" > "$4"
+ fi
+ return 0
+}
+
+do_todo() {
+ local n SKIP skip
+ SKIP=0
+ skip=$(grep '// \[todo\]' "$1")
+ [ "$skip" ] && SKIP=1
+ [ $SKIP = 0 ] && return 1
+ skip=$(echo "$skip" | cut -d ']' -f2 )
+ n=$(printf "% 4i" "$2")
+ if [ "$async" -eq 0 ]
+ then echo "ok $(printf "% 4i" "$n") $3 # Todo $skip"
+ else echo "ok $(printf "% 4i" "$n") $3 # Todo $skip" > "$4"
+ fi
+ return 0
+}
+
+test_gw(){
+ local n file log ret
+ n=$2
+ file=$1
+ log=${GWION_TEST_DIR}/${GWION_TEST_PREFIX}$(printf "%04i" "$n")
+ slog=${GWION_TEST_DIR}/${GWION_TEST_PREFIX}$(printf "%04i" "$n").std.log
+ elog=${GWION_TEST_DIR}/${GWION_TEST_PREFIX}$(printf "%04i" "$n").err.log
+ vlog=${GWION_TEST_DIR}/${GWION_TEST_PREFIX}$(printf "%04i" "$n").valgrind.log
+ rlog=${GWION_TEST_DIR}/${GWION_TEST_PREFIX}$(printf "%04i" "$n").log
+ if [ "$VALGRIND" == "NO_VALGRIND" ]
+ then ./"$PRG" "$GWOPT" -d "$DRIVER" "$file" > "$slog" 2>"$elog" |:
+ else
+ "$VALGRIND" --suppressions=help/supp --log-file="$vlog" \
+ ./"$PRG" "$GWOPT" -d "$DRIVER" "$file" > "$slog" 2>"$elog" |:
+ fi
+ ret=$?
+ #enable skip
+ do_skip "$1" "$n" "$file" "$rlog" && return 0
+ # enable todo
+ do_todo "$1" "$n" "$file" "$rlog" && return 0
+
+ [ $severity -lt 1 ] && success "$n" "$file" "$rlog" "$vlog" && return 0
+ assert_returns "$ret" "$log" || fail "$n" "$file" "$rlog" "$vlog" || return 1
+ [ $severity -lt 2 ] && success "$n" "$file" "$rlog" "$vlog" && return 0
+ assert_contain "$file" "$log" || fail "$n" "$file" "$rlog" "$vlog" || return 1
+ [ $severity -lt 3 ] && success "$n" "$file" "$rlog" "$vlog" && return 0
+ assert_exclude "$file" "$log" || fail "$n" "$file" "$rlog" "$vlog" || return 1
+ [ $severity -lt 4 ] && success "$n" "$file" "$rlog" "$vlog" && return 0
+ assert_rw "$file" "$log" || fail "$n" "$file" "$rlog" "$vlog" || return 1
+ [ $severity -lt 5 ] && success "$n" "$file" "$rlog" "$vlog" && return 0
+ assert_initial "$file" "$log" || fail "$n" "$file" "$rlog" "$vlog" || return 1
+ [ $severity -lt 6 ] && success "$n" "$file" "$rlog" "$vlog" && return 0
+ assert_syscall "$file" "$log" || fail "$n" "$file" "$rlog" "$vlog" || return 1
+ [ $severity -lt 7 ] && success "$n" "$file" "$rlog" "$vlog" && return 0
+ assert_free "$file" "$log" || fail "$n" "$file" "$rlog" "$vlog" || return 1
+ [ $severity -lt 8 ] && success "$n" "$file" "$rlog" "$vlog" && return 0
+ assert_mismatch "$file" "$log" || fail "$n" "$file" "$rlog" "$vlog" || return 1
+ [ $severity -lt 9 ] && success "$n" "$file" "$rlog" "$vlog" && return 0
+ assert_overlap "$file" "$log" || fail "$n" "$file" "$rlog" "$vlog" || return 1
+ [ $severity -lt 10 ] && success "$n" "$file" "$rlog" "$vlog" && return 0
+ assert_fishy "$file" "$log" || fail "$n" "$file" "$rlog" "$vlog" || return 1
+ [ $severity -lt 11 ] && success "$n" "$file" "$rlog" "$vlog" && return 0
+ assert_leak "$file" "$log" || fail "$n" "$file" "$rlog" "$vlog" || return 1
+ success "$n" "$file" "$rlog" && return 0
+}