1# Simulate io errors when encoding and decoding
2
3Import("env", "malloc_env")
4
5c = Copy("$TARGET", "$SOURCE")
6env.Command("alltypes.proto", "#alltypes/alltypes.proto", c)
7env.Command("io_errors.c", "#io_errors/io_errors.c", c)
8
9env.NanopbProto(["alltypes", "alltypes.options"])
10
11ioerr = env.Program(["io_errors.c", "alltypes.pb.c",
12                     "$COMMON/pb_encode_with_malloc.o",
13                     "$COMMON/pb_decode_with_malloc.o",
14                     "$COMMON/pb_common_with_malloc.o",
15                     "$COMMON/malloc_wrappers.o"])
16
17# Run tests under valgrind if available
18valgrind = env.WhereIs('valgrind')
19kwargs = {}
20if valgrind:
21    kwargs['COMMAND'] = valgrind
22    kwargs['ARGS'] = ["-q", "--error-exitcode=99", ioerr[0].abspath]
23
24env.RunTest("io_errors.output", [ioerr, "$BUILD/alltypes/encode_alltypes.output"], **kwargs)
25
26
27