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
18kwargs = {}
19if env.get("VALGRIND"):
20    kwargs['COMMAND'] = env['VALGRIND']
21    kwargs['ARGS'] = ["-q", "--error-exitcode=99", ioerr[0].abspath]
22
23env.RunTest("io_errors.output", [ioerr, "$BUILD/alltypes/encode_alltypes.output"], **kwargs)
24
25
26