version 0.9.26
diff --git a/asn1c/Makefile.am b/asn1c/Makefile.am
index 0125898..a369de3 100644
--- a/asn1c/Makefile.am
+++ b/asn1c/Makefile.am
@@ -23,5 +23,6 @@
 dist_man1_MANS = asn1c.1 unber.1 enber.1
 
 dist_check_SCRIPTS = check-xxber.sh check-parsing.sh
+TESTS_ENVIRONMENT= top_srcdir=${top_srcdir}
 TESTS = $(dist_check_SCRIPTS)
 CLEANFILES = .check-xxber.*.tmp .check-parsing.*.tmp
diff --git a/asn1c/Makefile.in b/asn1c/Makefile.in
index 13cd081..2fef605 100644
--- a/asn1c/Makefile.in
+++ b/asn1c/Makefile.in
@@ -189,6 +189,7 @@
 LIPO = @LIPO@
 LN_S = @LN_S@
 LTLIBOBJS = @LTLIBOBJS@
+MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
 MANIFEST_TOOL = @MANIFEST_TOOL@
 MKDIR_P = @MKDIR_P@
@@ -286,13 +287,14 @@
 noinst_HEADERS = sys-common.h
 dist_man1_MANS = asn1c.1 unber.1 enber.1
 dist_check_SCRIPTS = check-xxber.sh check-parsing.sh
+TESTS_ENVIRONMENT = top_srcdir=${top_srcdir}
 TESTS = $(dist_check_SCRIPTS)
 CLEANFILES = .check-xxber.*.tmp .check-parsing.*.tmp
 all: all-recursive
 
 .SUFFIXES:
 .SUFFIXES: .c .lo .o .obj
-$(srcdir)/Makefile.in:  $(srcdir)/Makefile.am  $(am__configure_deps)
+$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am  $(am__configure_deps)
 	@for dep in $?; do \
 	  case '$(am__configure_deps)' in \
 	    *$$dep*) \
@@ -317,9 +319,9 @@
 $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
 	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
 
-$(top_srcdir)/configure:  $(am__configure_deps)
+$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
 	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
-$(ACLOCAL_M4):  $(am__aclocal_m4_deps)
+$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
 	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
 $(am__aclocal_m4_deps):
 install-binPROGRAMS: $(bin_PROGRAMS)
diff --git a/asn1c/check-parsing.sh b/asn1c/check-parsing.sh
index ebbf399..7d81172 100755
--- a/asn1c/check-parsing.sh
+++ b/asn1c/check-parsing.sh
@@ -1,25 +1,43 @@
 #!/bin/sh
 
-tmpfile=".check-parsing.$$.tmp"
-
 # Test diff(1) capabilities
 diff -a . . 2>/dev/null && diffArgs="-a"		# Assume text files
 diff -u . . 2>/dev/null && diffArgs="$diffArgs -u"	# Unified diff output
 
 ec=0
 
-for ref in ../tests/*.asn1.-*; do
+set -o pipefail
+set -e
+
+PROCESSING=""
+print_status() {
+    echo "Error while processing $PROCESSING"
+}
+
+trap print_status ERR
+
+if [ "x${top_srcdir}" = "x" ]; then
+  top_srcdir=".."
+fi
+
+for ref in ${top_srcdir}/tests/*.asn1.-*; do
+	# Figure out the initial source file used to generate this output.
 	src=`echo "$ref" | sed -e 's/\.-[-a-zA-Z0-9=]*$//'`
+	# Figure out compiler flags used to create the file.
 	flags=`echo "$ref" | sed -e 's/.*\.-//'`
 	echo "Checking $src against $ref"
-	./asn1c -S../skeletons "-$flags" "$src" > "$tmpfile" || ec=$?
+	template=.tmp.check-parsing.$$
+	oldversion=${template}.old
+	newversion=${template}.new
+	PROCESSING="$ref (from $src)"
+	cat "$ref" | LANG=C sed -e 's/^found in .*/found in .../' > $oldversion
+	(./asn1c -S ${top_srcdir}/skeletons "-$flags" "$src" | LANG=C sed -e 's/^found in .*/found in .../' > "$newversion") || ec=$?
 	if [ $? = 0 ]; then
-		diff $diffArgs "$ref" "$tmpfile" || ec=$?
+		diff $diffArgs "$oldversion" "$newversion" || ec=$?
 	fi
-	if [ "$1" != "regenerate" ]; then
-		rm -f "$tmpfile"
-	else
-		mv "$tmpfile" "$ref"
+	rm -f $oldversion $newversion
+	if [ "$1" = "regenerate" ]; then
+		./asn1c -S ${top_srcdir}/skeletons "-$flags" "$src" > "$ref"
 	fi
 done
 
diff --git a/asn1c/tests/Makefile.am b/asn1c/tests/Makefile.am
index 5f05702..f780a4a 100644
--- a/asn1c/tests/Makefile.am
+++ b/asn1c/tests/Makefile.am
@@ -1,15 +1,15 @@
 
 dist_check_SCRIPTS = check-assembly.sh
 
-TESTS_ENVIRONMENT= CC="${CC}" CFLAGS="${TESTSUITE_CFLAGS} ${CFLAGS} -Wno-error=unused-variable" CXXFLAGS="${CXXFLAGS}" ./check-assembly.sh
+TESTS_ENVIRONMENT= CC="${CC}" CFLAGS="${TESTSUITE_CFLAGS} ${CFLAGS} -Wno-error=unused-variable" CXXFLAGS="${CXXFLAGS}" srcdir=${srcdir} top_srcdir=${top_srcdir} top_builddir=${top_builddir} ${srcdir}/check-assembly.sh
 
-TESTS = check-*.c
+TESTS = ${srcdir}/check-src/check-*.c
 if TEST_64BIT
-TESTS += check64-*.c
+TESTS += ${srcdir}/check-src/check64-*.c
 endif
 
 EXTRA_DIST =			\
-	check-*.c*		\
+	check-src/		\
 	data-62			\
 	data-70			\
 	data-119		\
diff --git a/asn1c/tests/Makefile.in b/asn1c/tests/Makefile.in
index 7204cc8..a191aa8 100644
--- a/asn1c/tests/Makefile.in
+++ b/asn1c/tests/Makefile.in
@@ -33,7 +33,7 @@
 POST_UNINSTALL = :
 build_triplet = @build@
 host_triplet = @host@
-@TEST_64BIT_TRUE@am__append_1 = check64-*.c
+@TEST_64BIT_TRUE@am__append_1 = ${srcdir}/check-src/check64-*.c
 subdir = asn1c/tests
 DIST_COMMON = README $(dist_check_SCRIPTS) $(srcdir)/Makefile.am \
 	$(srcdir)/Makefile.in
@@ -95,6 +95,7 @@
 LIPO = @LIPO@
 LN_S = @LN_S@
 LTLIBOBJS = @LTLIBOBJS@
+MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
 MANIFEST_TOOL = @MANIFEST_TOOL@
 MKDIR_P = @MKDIR_P@
@@ -174,10 +175,10 @@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
 dist_check_SCRIPTS = check-assembly.sh
-TESTS_ENVIRONMENT = CC="${CC}" CFLAGS="${TESTSUITE_CFLAGS} ${CFLAGS} -Wno-error=unused-variable" CXXFLAGS="${CXXFLAGS}" ./check-assembly.sh
-TESTS = check-*.c $(am__append_1)
+TESTS_ENVIRONMENT = CC="${CC}" CFLAGS="${TESTSUITE_CFLAGS} ${CFLAGS} -Wno-error=unused-variable" CXXFLAGS="${CXXFLAGS}" srcdir=${srcdir} top_srcdir=${top_srcdir} top_builddir=${top_builddir} ${srcdir}/check-assembly.sh
+TESTS = ${srcdir}/check-src/check-*.c $(am__append_1)
 EXTRA_DIST = \
-	check-*.c*		\
+	check-src/		\
 	data-62			\
 	data-70			\
 	data-119		\
@@ -186,7 +187,7 @@
 all: all-am
 
 .SUFFIXES:
-$(srcdir)/Makefile.in:  $(srcdir)/Makefile.am  $(am__configure_deps)
+$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am  $(am__configure_deps)
 	@for dep in $?; do \
 	  case '$(am__configure_deps)' in \
 	    *$$dep*) \
@@ -211,9 +212,9 @@
 $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
 	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
 
-$(top_srcdir)/configure:  $(am__configure_deps)
+$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
 	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
-$(ACLOCAL_M4):  $(am__aclocal_m4_deps)
+$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
 	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
 $(am__aclocal_m4_deps):
 
diff --git a/asn1c/tests/check-assembly.sh b/asn1c/tests/check-assembly.sh
index 5858f5b..bdcc7d9 100755
--- a/asn1c/tests/check-assembly.sh
+++ b/asn1c/tests/check-assembly.sh
@@ -10,11 +10,15 @@
 	exit
 fi
 
-# Compute the .asn1 spec name by the given file name.
-source=`echo "$1" | sed -e 's/.*\///'`
-testno=`echo "$source" | cut -f2 -d'-' | cut -f1 -d'.'`
+set -o pipefail
+set -e
 
-args=`echo "$source" | sed -e 's/\.c[c]*$//'`
+# Compute the .asn1 spec name by the given file name.
+source_full=$1
+source_short=`echo "$source_full" | sed -e 's/.*\///'`
+testno=`echo "$source_short" | cut -f2 -d'-' | cut -f1 -d'.'`
+
+args=`echo "$source_short" | sed -e 's/\.c[c]*$//'`
 testdir=test-${args}
 
 OFS=$IFS
@@ -24,16 +28,15 @@
 IFS=$OFS
 AFLAGS="$@"
 
-touch ${testdir}-FAILED		# Create this file to ease post mortem analysis
+# Assume the test fails. Will be removed when it passes well.
+touch ${testdir}-FAILED
 
-if [ ! -d $testdir ]; then
-	mkdir $testdir		|| exit $?
-fi
-cd $testdir			|| exit $?
-rm -f ./$source 2>/dev/null
-ln -fns ../$source		|| exit $?
+mkdir -p $testdir
+cd $testdir
+rm -f $source_short
+ln -fns ../$source_full
 
-asn_module=`echo ../../../tests/${testno}-*.asn1`
+asn_module=`echo ../${top_srcdir}/tests/${testno}-*.asn1`
 
 # Create a Makefile for the project.
 cat > Makefile <<EOM
@@ -41,6 +44,7 @@
 
 COMMON_FLAGS= -I. -DEMIT_ASN_DEBUG
 CFLAGS = \${COMMON_FLAGS} ${CFLAGS} -g -O0
+CPPFLAGS = -DSRCDIR=../${srcdir}
 CXXFLAGS = \${COMMON_FLAGS} ${CXXFLAGS}
 
 CC ?= ${CC}
@@ -48,11 +52,11 @@
 all: check-executable
 check-executable: compiled-module *.c*
 	@rm -f *.core
-	\$(CC) \$(CFLAGS) -o check-executable *.c* -lm
+	\$(CC) \$(CPPFLAGS) \$(CFLAGS) -o check-executable *.c* -lm
 
 # Compile the corresponding .asn1 spec.
-compiled-module: ${asn_module} ../../asn1c
-	../../asn1c -S ../../../skeletons -Wdebug-compiler	\\
+compiled-module: ${asn_module} ../${top_builddir}/asn1c/asn1c
+	../${top_builddir}/asn1c/asn1c -S ../${top_srcdir}/skeletons -Wdebug-compiler	\\
 		${AFLAGS} ${asn_module}
 	rm -f converter-sample.c
 	@touch compiled-module
@@ -69,8 +73,7 @@
 EOM
 
 # Perform building and checking
-make check || exit $?
+make check
 
+# Make sure the test is not marked as failed any longer.
 rm -f ../${testdir}-FAILED
-
-exit 0
diff --git a/asn1c/tests/check-03.-fwide-types.c b/asn1c/tests/check-src/check-03.-fwide-types.c
similarity index 100%
rename from asn1c/tests/check-03.-fwide-types.c
rename to asn1c/tests/check-src/check-03.-fwide-types.c
diff --git a/asn1c/tests/check-119.-fwide-types.-gen-PER.c b/asn1c/tests/check-src/check-119.-fwide-types.-gen-PER.c
similarity index 96%
rename from asn1c/tests/check-119.-fwide-types.-gen-PER.c
rename to asn1c/tests/check-src/check-119.-fwide-types.-gen-PER.c
index 5877d00..8e5c242 100644
--- a/asn1c/tests/check-119.-fwide-types.-gen-PER.c
+++ b/asn1c/tests/check-src/check-119.-fwide-types.-gen-PER.c
@@ -17,6 +17,14 @@
 
 #include <PDU.h>
 
+#ifndef SRCDIR
+#define SRCDIR_S ".."
+#else
+#define STRINGIFY_MACRO2(x) #x
+#define STRINGIFY_MACRO(x)  STRINGIFY_MACRO2(x)
+#define SRCDIR_S    STRINGIFY_MACRO(SRCDIR)
+#endif
+
 enum expectation {
 	EXP_OK,		/* Encoding/decoding must succeed */
 	EXP_CXER_EXACT,	/* Encoding/decoding using CXER must be exact */
@@ -311,7 +319,7 @@
 
 	fprintf(stderr, "\nProcessing file [../%s]\n", fname);
 
-	snprintf((char *)fbuf, sizeof(fbuf), "../data-119/%s", fname);
+	snprintf((char *)fbuf, sizeof(fbuf), SRCDIR_S "/data-119/%s", fname);
 	fp = fopen((char *)fbuf, "r");
 	assert(fp);
 
@@ -341,7 +349,7 @@
 		return 0;
 	}
 
-	dir = opendir("../data-119");
+	dir = opendir(SRCDIR_S "/data-119");
 	assert(dir);
 
 	/*
diff --git a/asn1c/tests/check-119.-gen-PER.c b/asn1c/tests/check-src/check-119.-gen-PER.c
similarity index 96%
rename from asn1c/tests/check-119.-gen-PER.c
rename to asn1c/tests/check-src/check-119.-gen-PER.c
index adcc6d9..a1f2f80 100644
--- a/asn1c/tests/check-119.-gen-PER.c
+++ b/asn1c/tests/check-src/check-119.-gen-PER.c
@@ -17,6 +17,14 @@
 
 #include <PDU.h>
 
+#ifndef SRCDIR
+#define SRCDIR_S ".."
+#else
+#define STRINGIFY_MACRO2(x) #x
+#define STRINGIFY_MACRO(x)  STRINGIFY_MACRO2(x)
+#define SRCDIR_S    STRINGIFY_MACRO(SRCDIR)
+#endif
+
 enum expectation {
 	EXP_OK,		/* Encoding/decoding must succeed */
 	EXP_CXER_EXACT,	/* Encoding/decoding using CXER must be exact */
@@ -313,7 +321,7 @@
 
 	fprintf(stderr, "\nProcessing file [../%s]\n", fname);
 
-	snprintf((char *)fbuf, sizeof(fbuf), "../data-119/%s", fname);
+	snprintf((char *)fbuf, sizeof(fbuf), SRCDIR_S "/data-119/%s", fname);
 	fp = fopen((char *)fbuf, "r");
 	assert(fp);
 
@@ -343,7 +351,7 @@
 		return 0;
 	}
 
-	dir = opendir("../data-119");
+	dir = opendir(SRCDIR_S "/data-119");
 	assert(dir);
 
 	/*
diff --git a/asn1c/tests/check-126.-gen-PER.c b/asn1c/tests/check-src/check-126.-gen-PER.c
similarity index 94%
rename from asn1c/tests/check-126.-gen-PER.c
rename to asn1c/tests/check-src/check-126.-gen-PER.c
index 81ebc0e..595a1db 100644
--- a/asn1c/tests/check-126.-gen-PER.c
+++ b/asn1c/tests/check-src/check-126.-gen-PER.c
@@ -16,6 +16,14 @@
 
 #include <PDU.h>
 
+#ifndef SRCDIR
+#define SRCDIR_S ".."
+#else
+#define STRINGIFY_MACRO2(x) #x
+#define STRINGIFY_MACRO(x)  STRINGIFY_MACRO2(x)
+#define SRCDIR_S    STRINGIFY_MACRO(SRCDIR)
+#endif
+
 static unsigned char buf[4096];
 static int buf_offset;
 
@@ -229,14 +237,14 @@
 static void
 compare_with_data_out(const char *fname, void *datap, size_t size) {
     char *data = datap;
-	char outName[256];
+	char outName[sizeof(SRCDIR_S) + 256];
 	unsigned char fbuf[1024];
 	size_t rd;
 	FILE *f;
 	char lastChar;
 	int mustfail, compare;
 
-	sprintf(outName, "../data-126/%s", fname);
+	sprintf(outName, SRCDIR_S "/data-126/%s", fname);
 	strcpy(outName + strlen(outName) - 3, ".out");
 
 	fprintf(stderr, "Comparing PER output with [%s]\n", outName);
@@ -304,7 +312,7 @@
  */
 static int
 process(const char *fname) {
-	unsigned char fbuf[4096];
+	unsigned char fbuf[sizeof(SRCDIR_S) + 4096];
 	char *ext = strrchr(fname, '.');
 	int rd;
 	FILE *fp;
@@ -314,7 +322,7 @@
 
 	fprintf(stderr, "\nProcessing file [../%s]\n", fname);
 
-	snprintf((char *)fbuf, sizeof(fbuf), "../data-126/%s", fname);
+	snprintf((char *)fbuf, sizeof(fbuf), SRCDIR_S "/data-126/%s", fname);
 	fp = fopen((char *)fbuf, "r");
 	assert(fp);
 
@@ -344,7 +352,7 @@
 		return 0;
 	}
 
-	dir = opendir("../data-126");
+	dir = opendir(SRCDIR_S "/data-126");
 	assert(dir);
 
 	/*
diff --git a/asn1c/tests/check-127.-gen-PER.c b/asn1c/tests/check-src/check-127.-gen-PER.c
similarity index 100%
rename from asn1c/tests/check-127.-gen-PER.c
rename to asn1c/tests/check-src/check-127.-gen-PER.c
diff --git a/asn1c/tests/check-131.-gen-PER.c b/asn1c/tests/check-src/check-131.-gen-PER.c
similarity index 100%
rename from asn1c/tests/check-131.-gen-PER.c
rename to asn1c/tests/check-src/check-131.-gen-PER.c
diff --git a/asn1c/tests/check-132.-gen-PER.c b/asn1c/tests/check-src/check-132.-gen-PER.c
similarity index 100%
rename from asn1c/tests/check-132.-gen-PER.c
rename to asn1c/tests/check-src/check-132.-gen-PER.c
diff --git a/asn1c/tests/check-133.-gen-PER.c b/asn1c/tests/check-src/check-133.-gen-PER.c
similarity index 100%
rename from asn1c/tests/check-133.-gen-PER.c
rename to asn1c/tests/check-src/check-133.-gen-PER.c
diff --git a/asn1c/tests/check-19.c b/asn1c/tests/check-src/check-19.c
similarity index 100%
rename from asn1c/tests/check-19.c
rename to asn1c/tests/check-src/check-19.c
diff --git a/asn1c/tests/check-22.-fwide-types.c b/asn1c/tests/check-src/check-22.-fwide-types.c
similarity index 100%
rename from asn1c/tests/check-22.-fwide-types.c
rename to asn1c/tests/check-src/check-22.-fwide-types.c
diff --git a/asn1c/tests/check-24.-fwide-types.c b/asn1c/tests/check-src/check-24.-fwide-types.c
similarity index 100%
rename from asn1c/tests/check-24.-fwide-types.c
rename to asn1c/tests/check-src/check-24.-fwide-types.c
diff --git a/asn1c/tests/check-25.-fwide-types.c b/asn1c/tests/check-src/check-25.-fwide-types.c
similarity index 100%
rename from asn1c/tests/check-25.-fwide-types.c
rename to asn1c/tests/check-src/check-25.-fwide-types.c
diff --git a/asn1c/tests/check-30.-fwide-types.c b/asn1c/tests/check-src/check-30.-fwide-types.c
similarity index 100%
rename from asn1c/tests/check-30.-fwide-types.c
rename to asn1c/tests/check-src/check-30.-fwide-types.c
diff --git a/asn1c/tests/check-31.-fwide-types.c b/asn1c/tests/check-src/check-31.-fwide-types.c
similarity index 100%
rename from asn1c/tests/check-31.-fwide-types.c
rename to asn1c/tests/check-src/check-31.-fwide-types.c
diff --git a/asn1c/tests/check-32.c b/asn1c/tests/check-src/check-32.c
similarity index 100%
rename from asn1c/tests/check-32.c
rename to asn1c/tests/check-src/check-32.c
diff --git a/asn1c/tests/check-33.c b/asn1c/tests/check-src/check-33.c
similarity index 100%
rename from asn1c/tests/check-33.c
rename to asn1c/tests/check-src/check-33.c
diff --git a/asn1c/tests/check-35.c b/asn1c/tests/check-src/check-35.c
similarity index 100%
rename from asn1c/tests/check-35.c
rename to asn1c/tests/check-src/check-35.c
diff --git a/asn1c/tests/check-39.c b/asn1c/tests/check-src/check-39.c
similarity index 100%
rename from asn1c/tests/check-39.c
rename to asn1c/tests/check-src/check-39.c
diff --git a/asn1c/tests/check-41.-fwide-types.c b/asn1c/tests/check-src/check-41.-fwide-types.c
similarity index 100%
rename from asn1c/tests/check-41.-fwide-types.c
rename to asn1c/tests/check-src/check-41.-fwide-types.c
diff --git a/asn1c/tests/check-41.c b/asn1c/tests/check-src/check-41.c
similarity index 100%
rename from asn1c/tests/check-41.c
rename to asn1c/tests/check-src/check-41.c
diff --git a/asn1c/tests/check-42.c b/asn1c/tests/check-src/check-42.c
similarity index 100%
rename from asn1c/tests/check-42.c
rename to asn1c/tests/check-src/check-42.c
diff --git a/asn1c/tests/check-43.c b/asn1c/tests/check-src/check-43.c
similarity index 100%
rename from asn1c/tests/check-43.c
rename to asn1c/tests/check-src/check-43.c
diff --git a/asn1c/tests/check-44.c b/asn1c/tests/check-src/check-44.c
similarity index 100%
rename from asn1c/tests/check-44.c
rename to asn1c/tests/check-src/check-44.c
diff --git a/asn1c/tests/check-46.c b/asn1c/tests/check-src/check-46.c
similarity index 100%
rename from asn1c/tests/check-46.c
rename to asn1c/tests/check-src/check-46.c
diff --git a/asn1c/tests/check-48.c b/asn1c/tests/check-src/check-48.c
similarity index 100%
rename from asn1c/tests/check-48.c
rename to asn1c/tests/check-src/check-48.c
diff --git a/asn1c/tests/check-50.c b/asn1c/tests/check-src/check-50.c
similarity index 100%
rename from asn1c/tests/check-50.c
rename to asn1c/tests/check-src/check-50.c
diff --git a/asn1c/tests/check-59.c b/asn1c/tests/check-src/check-59.c
similarity index 100%
rename from asn1c/tests/check-59.c
rename to asn1c/tests/check-src/check-59.c
diff --git a/asn1c/tests/check-60.c b/asn1c/tests/check-src/check-60.c
similarity index 100%
rename from asn1c/tests/check-60.c
rename to asn1c/tests/check-src/check-60.c
diff --git a/asn1c/tests/check-62.c b/asn1c/tests/check-src/check-62.c
similarity index 92%
rename from asn1c/tests/check-62.c
rename to asn1c/tests/check-src/check-62.c
index 27e1354..7c1864b 100644
--- a/asn1c/tests/check-62.c
+++ b/asn1c/tests/check-src/check-62.c
@@ -2,7 +2,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/types.h>
-#include <unistd.h>	/* for chdir(2) */
+#include <unistd.h>	/* for chdir(2), getcwd(3) */
 #include <string.h>
 #include <dirent.h>
 #include <assert.h>
@@ -10,6 +10,14 @@
 
 #include <T.h>
 
+#ifndef SRCDIR
+#define SRCDIR_S ".."
+#else
+#define STRINGIFY_MACRO2(x) #x
+#define STRINGIFY_MACRO(x)  STRINGIFY_MACRO2(x)
+#define SRCDIR_S    STRINGIFY_MACRO(SRCDIR)
+#endif
+
 enum expectation {
 	EXP_OK,		/* Encoding/decoding must succeed */
 	EXP_BROKEN,	/* Decoding must fail */
@@ -142,6 +150,7 @@
  */
 static int
 process(const char *fname) {
+	char prevdir[256];
 	unsigned char fbuf[4096];
 	char *ext = strrchr(fname, '.');
 	enum expectation expectation;
@@ -165,10 +174,11 @@
 
 	fprintf(stderr, "\nProcessing file [../%s]\n", fname);
 
-	ret = chdir("../data-62");
+	getcwd(prevdir, sizeof(prevdir));
+	ret = chdir(SRCDIR_S "/data-62");
 	assert(ret == 0);
 	fp = fopen(fname, "r");
-	ret = chdir("../test-check-62");
+	ret = chdir(prevdir);
 	assert(ret == 0);
 	assert(fp);
 
@@ -189,7 +199,7 @@
 	int processed_files = 0;
 	char *str;
 
-	dir = opendir("../data-62");
+	dir = opendir(SRCDIR_S "/data-62");
 	assert(dir);
 
 	str = getenv("DATA_62_FILE");
diff --git a/asn1c/tests/check-65.c b/asn1c/tests/check-src/check-65.c
similarity index 100%
rename from asn1c/tests/check-65.c
rename to asn1c/tests/check-src/check-65.c
diff --git a/asn1c/tests/check-70.-fwide-types.c b/asn1c/tests/check-src/check-70.-fwide-types.c
similarity index 94%
rename from asn1c/tests/check-70.-fwide-types.c
rename to asn1c/tests/check-src/check-70.-fwide-types.c
index 92db99c..3a42e99 100644
--- a/asn1c/tests/check-70.-fwide-types.c
+++ b/asn1c/tests/check-src/check-70.-fwide-types.c
@@ -8,7 +8,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/types.h>
-#include <unistd.h>	/* for chdir(2) */
+#include <unistd.h>	/* for chdir(2), getcwd(3) */
 #include <string.h>
 #include <ctype.h>
 #include <dirent.h>
@@ -17,6 +17,14 @@
 
 #include <PDU.h>
 
+#ifndef SRCDIR
+#define SRCDIR_S ".."
+#else
+#define STRINGIFY_MACRO2(x) #x
+#define STRINGIFY_MACRO(x)  STRINGIFY_MACRO2(x)
+#define SRCDIR_S    STRINGIFY_MACRO(SRCDIR)
+#endif
+
 enum expectation {
 	EXP_OK,		/* Encoding/decoding must succeed */
 	EXP_CXER_EXACT,	/* Encoding/decoding using CXER must be exact */
@@ -250,6 +258,7 @@
  */
 static int
 process(const char *fname) {
+	char prevdir[256];
 	unsigned char fbuf[4096];
 	char *ext = strrchr(fname, '.');
 	enum expectation expectation;
@@ -275,10 +284,11 @@
 
 	fprintf(stderr, "\nProcessing file [../%s]\n", fname);
 
-	ret = chdir("../data-70");
+	getcwd(prevdir, sizeof(prevdir));
+	ret = chdir(SRCDIR_S "/data-70");
 	assert(ret == 0);
 	fp = fopen(fname, "r");
-	ret = chdir("../test-check-70.-fwide-types");
+	ret = chdir(prevdir);
 	assert(ret == 0);
 	assert(fp);
 
@@ -306,7 +316,7 @@
 		return 0;
 	}
 
-	dir = opendir("../data-70");
+	dir = opendir(SRCDIR_S "/data-70");
 	assert(dir);
 
 	/*
diff --git a/asn1c/tests/check-70.c b/asn1c/tests/check-src/check-70.c
similarity index 94%
rename from asn1c/tests/check-70.c
rename to asn1c/tests/check-src/check-70.c
index 431a21a..d09f095 100644
--- a/asn1c/tests/check-70.c
+++ b/asn1c/tests/check-src/check-70.c
@@ -8,7 +8,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/types.h>
-#include <unistd.h>	/* for chdir(2) */
+#include <unistd.h>	/* for chdir(2), getcwd(3) */
 #include <string.h>
 #include <dirent.h>
 #include <ctype.h>	/* for isspace(3) */
@@ -17,6 +17,14 @@
 
 #include <PDU.h>
 
+#ifndef SRCDIR
+#define SRCDIR_S ".."
+#else
+#define STRINGIFY_MACRO2(x) #x
+#define STRINGIFY_MACRO(x)  STRINGIFY_MACRO2(x)
+#define SRCDIR_S    STRINGIFY_MACRO(SRCDIR)
+#endif
+
 enum expectation {
 	EXP_OK,		/* Encoding/decoding must succeed */
 	EXP_BROKEN,	/* Decoding must fail */
@@ -226,6 +234,7 @@
  */
 static int
 process(const char *fname) {
+	char prevdir[256];
 	unsigned char fbuf[4096];
 	char *ext = strrchr(fname, '.');
 	enum expectation expectation;
@@ -249,10 +258,11 @@
 
 	fprintf(stderr, "\nProcessing file [../%s]\n", fname);
 
-	ret = chdir("../data-70");
+	getcwd(prevdir, sizeof(prevdir));
+	ret = chdir(SRCDIR_S "/data-70");
 	assert(ret == 0);
 	fp = fopen(fname, "r");
-	ret = chdir("../test-check-70");
+	ret = chdir(prevdir);
 	assert(ret == 0);
 	assert(fp);
 
@@ -278,7 +288,7 @@
 	if(str && strncmp(str, "data-70-", 8) == 0)
 		process(str);
 
-	dir = opendir("../data-70");
+	dir = opendir(SRCDIR_S "/data-70");
 	assert(dir);
 
 	/*
diff --git a/asn1c/tests/check-72.-fcompound-names.c b/asn1c/tests/check-src/check-72.-fcompound-names.c
similarity index 100%
rename from asn1c/tests/check-72.-fcompound-names.c
rename to asn1c/tests/check-src/check-72.-fcompound-names.c
diff --git a/asn1c/tests/check-73.c b/asn1c/tests/check-src/check-73.c
similarity index 100%
rename from asn1c/tests/check-73.c
rename to asn1c/tests/check-src/check-73.c
diff --git a/asn1c/tests/check-92.-findirect-choice.c b/asn1c/tests/check-src/check-92.-findirect-choice.c
similarity index 100%
rename from asn1c/tests/check-92.-findirect-choice.c
rename to asn1c/tests/check-src/check-92.-findirect-choice.c
diff --git a/asn1c/tests/check-92.c b/asn1c/tests/check-src/check-92.c
similarity index 100%
rename from asn1c/tests/check-92.c
rename to asn1c/tests/check-src/check-92.c
diff --git a/asn1c/tests/check64-134.-gen-PER.c b/asn1c/tests/check-src/check64-134.-gen-PER.c
similarity index 100%
rename from asn1c/tests/check64-134.-gen-PER.c
rename to asn1c/tests/check-src/check64-134.-gen-PER.c