[freenos] r424 committed - Implemented initial regression tests....

  • From: freenos@xxxxxxxxxxxxxx
  • To: freenos@xxxxxxxxxxxxx
  • Date: Mon, 25 Oct 2010 22:59:31 +0000

Revision: 424
Author: nieklinnenbank
Date: Mon Oct 25 15:56:29 2010
Log: Implemented initial regression tests.
The first regression test is for the linked list macros.
Each program, library or server may put regression tests
under the regress/ directory. Regression tests may be for
the host and/or the target.

http://code.google.com/p/freenos/source/detail?r=424

Added:
 /branches/scratch/lib/libc/assert.h
 /branches/scratch/regress
 /branches/scratch/regress/SConscript
 /branches/scratch/regress/include
 /branches/scratch/regress/include/SConscript
 /branches/scratch/regress/include/list.c
Modified:
 /branches/scratch/SConstruct

=======================================
--- /dev/null
+++ /branches/scratch/lib/libc/assert.h Mon Oct 25 15:56:29 2010
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2010 Niek Linnenbank
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __LIBC_ASSERT_H
+#define __LIBC_ASSERT_H
+
+#include "stdio.h"
+#include "stdlib.h"
+#include "stddef.h"
+
+/**
+ * @defgroup libc libc (ISO C99)
+ * @{
+ */
+
+/**
+ * @brief Insert program diagnostics.
+ *
+ * The assert() macro shall insert diagnostics into programs; it shall
+ * expand to a void expression. When it is executed, if expression
+ * (which shall have a scalar type) is false (that is, compares equal to 0), + * assert() shall write information about the particular call that failed on
+ * stderr and shall call abort().
+ *
+ * The information written about the call that failed shall include the text + * of the argument, the name of the source file, the source file line number, + * and the name of the enclosing function; the latter are, respectively, the
+ * values of the preprocessing macros __FILE__ and __LINE__ and of the
+ * identifier __func__.
+ *
+ * Forcing a definition of the name NDEBUG, either from the compiler command
+ * line or with the preprocessor control statement #define NDEBUG ahead of
+ * the #include <assert.h> statement, shall stop assertions from being
+ * compiled into the program.
+ *
+ * @param exp Boolean expression.
+ * @return The assert() macro shall not return a value.
+ */
+#ifdef NDEBUG
+#define assert(ignore) ((void) 0)
+#else
+#define assert(exp) \
+    if (!(exp)) \
+    { \
+        printf("[%s:%d]: *** Assertion `%s' failed ***\n", \
+                __FILE__, __LINE__, #exp); \
+       exit(1); \
+    }
+#endif
+
+/**
+ * @}
+ */
+
+#endif /* __LIBC_ASSERT_H */
=======================================
--- /dev/null
+++ /branches/scratch/regress/SConscript        Mon Oct 25 15:56:29 2010
@@ -0,0 +1,20 @@
+#
+# Copyright (C) 2010 Niek Linnenbank
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+Import('build_env')
+
+SConscript(dirs = [ 'include' ])
=======================================
--- /dev/null
+++ /branches/scratch/regress/include/SConscript        Mon Oct 25 15:56:29 2010
@@ -0,0 +1,25 @@
+#
+# Copyright (C) 2010 Niek Linnenbank
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+Import('build_env')
+
+env = build_env.Clone()
+
+if build_env['ARCH'] != 'host':
+    env.UseLibraries([ 'libcrt', 'libposix', 'libc' ])
+
+env.Program('list.c')
=======================================
--- /dev/null
+++ /branches/scratch/regress/include/list.c    Mon Oct 25 15:56:29 2010
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2010 Niek Linnenbank
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <assert.h>
+#include <list.h>
+
+struct parent
+{
+    LIST_HEAD(child_head, child) childs;
+};
+
+struct child
+{
+    int id;
+    LIST_ENTRY(child) next;
+};
+
+int main(int argc, char **argv)
+{
+    struct parent p1;
+    struct child  c1, c2, c3;
+
+    /* Initialize a list of childs. */
+    c1.id = 1;
+    c2.id = 2;
+    c3.id = 3;
+
+    /* Initialize the list head at parent. */
+    LIST_INIT(&p1.childs);
+    assert(LIST_EMPTY(&p1.childs));
+    assert(LIST_FIRST(&p1.childs) == NULL);
+    assert(LIST_LAST(&p1.childs)  == NULL);
+
+    /* Add first child at the head. */
+    LIST_INSERT_HEAD(&p1.childs, &c1, next);
+    assert(!LIST_EMPTY(&p1.childs));
+    assert(LIST_FIRST(&p1.childs) == &c1);
+    assert(LIST_LAST(&p1.childs)  == &c1);
+    assert(LIST_NEXT(&c1, next)   == NULL);
+    assert(LIST_PREV(&c1, next)   == NULL);
+    return 0;
+}
=======================================
--- /branches/scratch/SConstruct        Sun Oct 10 16:06:55 2010
+++ /branches/scratch/SConstruct        Mon Oct 25 15:56:29 2010
@@ -30,9 +30,11 @@
 VariantDir(target['BUILDROOT'] + '/lib', '#lib', duplicate = 0)
 VariantDir(target['BUILDROOT'] + '/bin', '#bin', duplicate = 0)
 VariantDir(target['BUILDROOT'] + '/server', '#server', duplicate = 0)
+VariantDir(target['BUILDROOT'] + '/regress', '#regress', duplicate = 0)
 SConscript(target['BUILDROOT'] + '/lib/SConscript')
 SConscript(target['BUILDROOT'] + '/bin/SConscript')
 SConscript(target['BUILDROOT'] + '/server/SConscript')
+SConscript(target['BUILDROOT'] + '/regress/SConscript')

 #
 # Host build
@@ -43,8 +45,10 @@
 # Build programs and libraries.
 VariantDir(host['BUILDROOT'] + '/lib', '#lib', duplicate = 0)
 VariantDir(host['BUILDROOT'] + '/bin', '#bin', duplicate = 0)
+VariantDir(host['BUILDROOT'] + '/regress', '#regress', duplicate = 0)
 SConscript(host['BUILDROOT'] + '/lib/SConscript')
 SConscript(host['BUILDROOT'] + '/bin/SConscript')
+SConscript(host['BUILDROOT'] + '/regress/SConscript')

 #
 # Kernel build

Other related posts:

  • » [freenos] r424 committed - Implemented initial regression tests.... - freenos