Move malloc support to tests/common directory
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>
Fri, 26 Dec 2014 15:34:45 +0000 (17:34 +0200)
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>
Fri, 26 Dec 2014 15:34:45 +0000 (17:34 +0200)
tests/SConstruct
tests/alltypes_pointer/SConscript
tests/common/SConscript
tests/fuzztest/SConscript
tests/io_errors_pointers/SConscript

index 1890670..9092d4f 100644 (file)
@@ -136,12 +136,18 @@ elif 'g++' in env['CXX'] or 'gcc' in env['CXX']:
     env.Append(CXXFLAGS = '-g -Wall -Werror -Wextra -Wno-missing-field-initializers')
 elif 'cl' in env['CXX']:
     env.Append(CXXFLAGS = '/Zi /W2 /WX')
     env.Append(CXXFLAGS = '-g -Wall -Werror -Wextra -Wno-missing-field-initializers')
 elif 'cl' in env['CXX']:
     env.Append(CXXFLAGS = '/Zi /W2 /WX')
-    
+
 # Now include the SConscript files from all subdirectories
 import os.path
 env['VARIANT_DIR'] = 'build'
 env['BUILD'] = '#' + env['VARIANT_DIR']
 env['COMMON'] = '#' + env['VARIANT_DIR'] + '/common'
 # Now include the SConscript files from all subdirectories
 import os.path
 env['VARIANT_DIR'] = 'build'
 env['BUILD'] = '#' + env['VARIANT_DIR']
 env['COMMON'] = '#' + env['VARIANT_DIR'] + '/common'
+
+# Include common/SConscript first to make sure its exports are available
+# to other SConscripts.
+SConscript("common/SConscript", exports = 'env', variant_dir = env['VARIANT_DIR'] + '/common')
+
 for subdir in Glob('*/SConscript') + Glob('regression/*/SConscript'):
 for subdir in Glob('*/SConscript') + Glob('regression/*/SConscript'):
+    if str(subdir).startswith("common"): continue
     SConscript(subdir, exports = 'env', variant_dir = env['VARIANT_DIR'] + '/' + os.path.dirname(str(subdir)))
 
     SConscript(subdir, exports = 'env', variant_dir = env['VARIANT_DIR'] + '/' + os.path.dirname(str(subdir)))
 
index 8fcf197..52856f6 100644 (file)
@@ -1,31 +1,22 @@
 # Encode the AllTypes message using pointers for all fields, and verify the
 # output against the normal AllTypes test case.
 
 # Encode the AllTypes message using pointers for all fields, and verify the
 # output against the normal AllTypes test case.
 
-Import("env")
-
-# We need our own pb_decode.o for the malloc support
-env = env.Clone()
-env.Append(CPPDEFINES = {'PB_ENABLE_MALLOC': 1});
-
-# Disable libmudflap, because it will confuse valgrind
-# and other memory leak detection tools.
-if '-fmudflap' in env["CCFLAGS"]:
-    env["CCFLAGS"].remove("-fmudflap")
-    env["LINKFLAGS"].remove("-fmudflap")
-    env["LIBS"].remove("mudflap")
-
-strict = env.Clone()
-strict.Append(CFLAGS = strict['CORECFLAGS'])
-strict.Object("pb_decode_with_malloc.o", "$NANOPB/pb_decode.c")
-strict.Object("pb_encode_with_malloc.o", "$NANOPB/pb_encode.c")
-strict.Object("pb_common_with_malloc.o", "$NANOPB/pb_common.c")
+Import("env", "malloc_env")
 
 c = Copy("$TARGET", "$SOURCE")
 env.Command("alltypes.proto", "#alltypes/alltypes.proto", c)
 
 env.NanopbProto(["alltypes", "alltypes.options"])
 
 c = Copy("$TARGET", "$SOURCE")
 env.Command("alltypes.proto", "#alltypes/alltypes.proto", c)
 
 env.NanopbProto(["alltypes", "alltypes.options"])
-enc = env.Program(["encode_alltypes_pointer.c", "alltypes.pb.c", "pb_encode_with_malloc.o", "pb_common_with_malloc.o"])
-dec = env.Program(["decode_alltypes_pointer.c", "alltypes.pb.c", "pb_decode_with_malloc.o", "pb_common_with_malloc.o"])
+enc = malloc_env.Program(["encode_alltypes_pointer.c",
+                          "alltypes.pb.c",
+                          "$COMMON/pb_encode_with_malloc.o",
+                          "$COMMON/pb_common_with_malloc.o",
+                          "$COMMON/malloc_wrappers.o"])
+dec = malloc_env.Program(["decode_alltypes_pointer.c",
+                          "alltypes.pb.c",
+                          "$COMMON/pb_decode_with_malloc.o",
+                          "$COMMON/pb_common_with_malloc.o",
+                          "$COMMON/malloc_wrappers.o"])
 
 # Encode and compare results to non-pointer alltypes test case
 env.RunTest(enc)
 
 # Encode and compare results to non-pointer alltypes test case
 env.RunTest(enc)
index 4581bea..a202ca4 100644 (file)
@@ -8,6 +8,7 @@ env.NanopbProto("unittestproto")
 # Protocol definitions for basic_buffer/stream tests
 env.NanopbProto("person")
 
 # Protocol definitions for basic_buffer/stream tests
 env.NanopbProto("person")
 
+#--------------------------------------------
 # Binaries of the pb_decode.c and pb_encode.c
 # These are built using more strict warning flags.
 strict = env.Clone()
 # Binaries of the pb_decode.c and pb_encode.c
 # These are built using more strict warning flags.
 strict = env.Clone()
@@ -16,6 +17,32 @@ strict.Object("pb_decode.o", "$NANOPB/pb_decode.c")
 strict.Object("pb_encode.o", "$NANOPB/pb_encode.c")
 strict.Object("pb_common.o", "$NANOPB/pb_common.c")
 
 strict.Object("pb_encode.o", "$NANOPB/pb_encode.c")
 strict.Object("pb_common.o", "$NANOPB/pb_common.c")
 
+#-----------------------------------------------
+# Binaries of pb_decode etc. with malloc support
+# Uses malloc_wrappers.c to count allocations.
+malloc_env = env.Clone()
+malloc_env.Append(CPPDEFINES = {'PB_ENABLE_MALLOC': 1,
+                                'PB_SYSTEM_HEADER': '\\"malloc_wrappers_syshdr.h\\"'})
+malloc_env.Append(CPPPATH = ["$COMMON"])
+
+if 'SYSHDR' in malloc_env:
+    malloc_env.Append(CPPDEFINES = {'PB_OLD_SYSHDR': malloc_env['SYSHDR']})
+
+# Disable libmudflap, because it will confuse valgrind
+# and other memory leak detection tools.
+if '-fmudflap' in env["CCFLAGS"]:
+    malloc_env["CCFLAGS"].remove("-fmudflap")
+    malloc_env["LINKFLAGS"].remove("-fmudflap")
+    malloc_env["LIBS"].remove("mudflap")
+
+malloc_strict = malloc_env.Clone()
+malloc_strict.Append(CFLAGS = malloc_strict['CORECFLAGS'])
+malloc_strict.Object("pb_decode_with_malloc.o", "$NANOPB/pb_decode.c")
+malloc_strict.Object("pb_encode_with_malloc.o", "$NANOPB/pb_encode.c")
+malloc_strict.Object("pb_common_with_malloc.o", "$NANOPB/pb_common.c")
+
 mw = env.Object("malloc_wrappers.o", "malloc_wrappers.c")
 Depends(mw, ["malloc_wrappers_syshdr.h"])
 
 mw = env.Object("malloc_wrappers.o", "malloc_wrappers.c")
 Depends(mw, ["malloc_wrappers_syshdr.h"])
 
+Export("malloc_env")
+
index 346ccab..35b697f 100644 (file)
@@ -1,30 +1,9 @@
 # Run a fuzz test to verify robustness against corrupted/malicious data.
 
 # Run a fuzz test to verify robustness against corrupted/malicious data.
 
-Import("env")
-
-# We need our own pb_decode.o for the malloc support
-env = env.Clone()
-env.Append(CPPDEFINES = {'PB_ENABLE_MALLOC': 1,
-                         'PB_SYSTEM_HEADER': '\\"malloc_wrappers_syshdr.h\\"'})
-env.Append(CPPPATH = [".", "$COMMON"])
-
-if 'SYSHDR' in env:
-    env.Append(CPPDEFINES = {'PB_OLD_SYSHDR': env['SYSHDR']})
-
-# Disable libmudflap, because it will confuse valgrind
-# and other memory leak detection tools.
-if '-fmudflap' in env["CCFLAGS"]:
-    env["CCFLAGS"].remove("-fmudflap")
-    env["LINKFLAGS"].remove("-fmudflap")
-    env["LIBS"].remove("mudflap")
-
-strict = env.Clone()
-strict.Append(CFLAGS = strict['CORECFLAGS'])
-strict.Object("pb_decode_with_malloc.o", "$NANOPB/pb_decode.c")
-strict.Object("pb_encode_with_malloc.o", "$NANOPB/pb_encode.c")
-strict.Object("pb_common_with_malloc.o", "$NANOPB/pb_common.c")
+Import("env", "malloc_env")
 
 # We want both pointer and static versions of the AllTypes message
 
 # We want both pointer and static versions of the AllTypes message
+# Prefix them with package name.
 env.Command("alltypes_static.proto", "#alltypes/alltypes.proto",
             lambda target, source, env:
                 open(str(target[0]), 'w').write("package alltypes_static;\n"
 env.Command("alltypes_static.proto", "#alltypes/alltypes.proto",
             lambda target, source, env:
                 open(str(target[0]), 'w').write("package alltypes_static;\n"
@@ -36,22 +15,22 @@ env.Command("alltypes_pointer.proto", "#alltypes/alltypes.proto",
 
 p1 = env.NanopbProto(["alltypes_pointer", "alltypes_pointer.options"])
 p2 = env.NanopbProto(["alltypes_static", "alltypes_static.options"])
 
 p1 = env.NanopbProto(["alltypes_pointer", "alltypes_pointer.options"])
 p2 = env.NanopbProto(["alltypes_static", "alltypes_static.options"])
-fuzz = env.Program(["fuzztest.c",
+fuzz = malloc_env.Program(["fuzztest.c",
                     "alltypes_pointer.pb.c",
                     "alltypes_static.pb.c",
                     "alltypes_pointer.pb.c",
                     "alltypes_static.pb.c",
-                    "pb_encode_with_malloc.o",
-                    "pb_decode_with_malloc.o",
-                    "pb_common_with_malloc.o",
+                    "$COMMON/pb_encode_with_malloc.o",
+                    "$COMMON/pb_decode_with_malloc.o",
+                    "$COMMON/pb_common_with_malloc.o",
                     "$COMMON/malloc_wrappers.o"])
 
 env.RunTest(fuzz)
 
                     "$COMMON/malloc_wrappers.o"])
 
 env.RunTest(fuzz)
 
-fuzzstub = env.Program(["fuzzstub.c",
+fuzzstub = malloc_env.Program(["fuzzstub.c",
                     "alltypes_pointer.pb.c",
                     "alltypes_static.pb.c",
                     "alltypes_pointer.pb.c",
                     "alltypes_static.pb.c",
-                    "pb_encode_with_malloc.o",
-                    "pb_decode_with_malloc.o",
-                    "pb_common_with_malloc.o",
+                    "$COMMON/pb_encode_with_malloc.o",
+                    "$COMMON/pb_decode_with_malloc.o",
+                    "$COMMON/pb_common_with_malloc.o",
                     "$COMMON/malloc_wrappers.o"])
 
 
                     "$COMMON/malloc_wrappers.o"])
 
 
index 0b96177..8d23f60 100644 (file)
@@ -1,23 +1,6 @@
 # Simulate io errors when encoding and decoding
 
 # Simulate io errors when encoding and decoding
 
-Import("env")
-
-# We need our own pb_decode.o for the malloc support
-env = env.Clone()
-env.Append(CPPDEFINES = {'PB_ENABLE_MALLOC': 1});
-
-# Disable libmudflap, because it will confuse valgrind
-# and other memory leak detection tools.
-if '-fmudflap' in env["CCFLAGS"]:
-    env["CCFLAGS"].remove("-fmudflap")
-    env["LINKFLAGS"].remove("-fmudflap")
-    env["LIBS"].remove("mudflap")
-
-strict = env.Clone()
-strict.Append(CFLAGS = strict['CORECFLAGS'])
-strict.Object("pb_decode_with_malloc.o", "$NANOPB/pb_decode.c")
-strict.Object("pb_encode_with_malloc.o", "$NANOPB/pb_encode.c")
-strict.Object("pb_common_with_malloc.o", "$NANOPB/pb_common.c")
+Import("env", "malloc_env")
 
 c = Copy("$TARGET", "$SOURCE")
 env.Command("alltypes.proto", "#alltypes/alltypes.proto", c)
 
 c = Copy("$TARGET", "$SOURCE")
 env.Command("alltypes.proto", "#alltypes/alltypes.proto", c)
@@ -26,9 +9,10 @@ env.Command("io_errors.c", "#io_errors/io_errors.c", c)
 env.NanopbProto(["alltypes", "alltypes.options"])
 
 ioerr = env.Program(["io_errors.c", "alltypes.pb.c",
 env.NanopbProto(["alltypes", "alltypes.options"])
 
 ioerr = env.Program(["io_errors.c", "alltypes.pb.c",
-                     "pb_encode_with_malloc.o",
-                     "pb_decode_with_malloc.o",
-                     "pb_common_with_malloc.o"])
+                     "$COMMON/pb_encode_with_malloc.o",
+                     "$COMMON/pb_decode_with_malloc.o",
+                     "$COMMON/pb_common_with_malloc.o",
+                     "$COMMON/malloc_wrappers.o"])
 
 # Run tests under valgrind if available
 valgrind = env.WhereIs('valgrind')
 
 # Run tests under valgrind if available
 valgrind = env.WhereIs('valgrind')