OLD | NEW |
| (Empty) |
1 | |
2 # Copyright 2009 The Native Client Authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can | |
4 # be found in the LICENSE file. | |
5 | |
6 import os | |
7 import sys | |
8 sys.path.append(os.path.join(os.path.dirname(__file__), | |
9 "..", "..", "tests")) | |
10 | |
11 import subprocess | |
12 import unittest | |
13 | |
14 from testutils import write_file | |
15 import testutils | |
16 | |
17 | |
18 def run_ncval(input_file): | |
19 testutils.check_call(["ncval", input_file], stdout=open(os.devnull, "w")) | |
20 | |
21 | |
22 class ToolchainTests(testutils.TempDirTestCase): | |
23 | |
24 def test_ncval_returns_errors(self): | |
25 # Check that ncval returns a non-zero return code when there is a | |
26 # validation failure. | |
27 code = """ | |
28 int main() { | |
29 #ifdef __i386__ | |
30 __asm__("ret"); | |
31 #else | |
32 # error Update this test for other architectures! | |
33 #endif | |
34 return 0; | |
35 } | |
36 """ | |
37 temp_dir = self.make_temp_dir() | |
38 write_file(os.path.join(temp_dir, "code.c"), code) | |
39 testutils.check_call(["nacl-gcc", os.path.join(temp_dir, "code.c"), | |
40 "-o", os.path.join(temp_dir, "prog")]) | |
41 rc = subprocess.call(["ncval", os.path.join(temp_dir, "prog")], | |
42 stdout=open(os.devnull, "w")) | |
43 self.assertEquals(rc, 1) | |
44 | |
45 def test_custom_linker_scripts_via_search_path(self): | |
46 # Check that the linker will pick up linker scripts from the | |
47 # "ldscripts" directory in the library search path (which is | |
48 # specified with -L). | |
49 # To test this, try to link to a symbol that is defined in our | |
50 # example linker script. | |
51 temp_dir = self.make_temp_dir() | |
52 os.mkdir(os.path.join(temp_dir, "ldscripts")) | |
53 write_file(os.path.join(temp_dir, "ldscripts", "elf_nacl.x"), """ | |
54 foo = 0x1234; | |
55 """) | |
56 write_file(os.path.join(temp_dir, "prog.c"), """ | |
57 void foo(); | |
58 int _start() { | |
59 foo(); | |
60 return 0; | |
61 } | |
62 """) | |
63 testutils.check_call(["nacl-gcc", "-nostartfiles", "-nostdlib", | |
64 "-L%s" % temp_dir, | |
65 os.path.join(temp_dir, "prog.c"), | |
66 "-o", os.path.join(temp_dir, "prog")]) | |
67 | |
68 | |
69 if __name__ == "__main__": | |
70 unittest.main() | |
OLD | NEW |