Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(762)

Side by Side Diff: test/mjsunit/d8-os.js

Issue 7491057: Make d8-os test less flaky. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009 the V8 project authors. All rights reserved. 1 // Copyright 2009 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 12 matching lines...) Expand all
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 // Test the OS module of d8. This test only makes sense with d8. It 28 // Test the OS module of d8. This test only makes sense with d8. It
29 // only does non-trivial work on Unix since os.system() is not currently 29 // only does non-trivial work on Unix since os.system() is not currently
30 // implemented on Windows, and even if it were then many of the things 30 // implemented on Windows, and even if it were then many of the things
31 // we are calling would not be available. 31 // we are calling would not be available.
32 32
33 var TEST_DIR = "d8-os-test-directory-" + ((Math.random() * 65535) | 0);
34
35
33 function arg_error(str) { 36 function arg_error(str) {
34 try { 37 try {
35 eval(str); 38 eval(str);
36 } catch (e) { 39 } catch (e) {
37 assertTrue(/rgument/.test(e), str); 40 assertTrue(/rgument/.test(e), str);
38 } 41 }
39 } 42 }
40 43
41 44
42 function str_error(str) { 45 function str_error(str) {
43 var e = new Object(); 46 var e = new Object();
44 e.toString = function() { throw new Error("foo bar"); } 47 e.toString = function() { throw new Error("foo bar"); }
45 try { 48 try {
46 eval(str); 49 eval(str);
47 } catch (exception) { 50 } catch (exception) {
48 assertTrue(/tring conversion/.test(exception), str); 51 assertTrue(/tring conversion/.test(exception), str);
49 } 52 }
50 } 53 }
51 54
52 55
53 if (this.os && os.system) { 56 if (this.os && os.system) {
54 try { 57 try {
55 // Delete the dir if it is lying around from last time. 58 // Delete the dir if it is lying around from last time.
56 os.system("ls", ["d8-os-test-directory"]); 59 os.system("ls", [TEST_DIR]);
57 os.system("rm", ["-r", "d8-os-test-directory"]); 60 os.system("rm", ["-r", TEST_DIR]);
58 } catch (e) { 61 } catch (e) {
59 } 62 }
60 os.mkdirp("d8-os-test-directory"); 63 os.mkdirp(TEST_DIR);
61 os.chdir("d8-os-test-directory"); 64 os.chdir(TEST_DIR);
62 // Check the chdir worked. 65 try {
63 os.system('ls', ['../d8-os-test-directory']); 66 // Check the chdir worked.
64 // Simple create dir. 67 os.system('ls', ['../' + TEST_DIR]);
65 os.mkdirp("dir"); 68 // Simple create dir.
66 // Create dir in dir. 69 os.mkdirp("dir");
67 os.mkdirp("dir/foo"); 70 // Create dir in dir.
68 // Check that they are there. 71 os.mkdirp("dir/foo");
69 os.system('ls', ['dir/foo']); 72 // Check that they are there.
70 // Check that we can detect when something is not there. 73 os.system('ls', ['dir/foo']);
71 assertThrows("os.system('ls', ['dir/bar']);", "dir not there"); 74 // Check that we can detect when something is not there.
72 // Check that mkdirp makes intermediate directories. 75 assertThrows("os.system('ls', ['dir/bar']);", "dir not there");
73 os.mkdirp("dir2/foo"); 76 // Check that mkdirp makes intermediate directories.
74 os.system("ls", ["dir2/foo"]); 77 os.mkdirp("dir2/foo");
75 // Check that mkdirp doesn't mind if the dir is already there. 78 os.system("ls", ["dir2/foo"]);
76 os.mkdirp("dir2/foo"); 79 // Check that mkdirp doesn't mind if the dir is already there.
77 os.mkdirp("dir2/foo/"); 80 os.mkdirp("dir2/foo");
78 // Check that mkdirp can cope with trailing / 81 os.mkdirp("dir2/foo/");
79 os.mkdirp("dir3/"); 82 // Check that mkdirp can cope with trailing /
80 os.system("ls", ["dir3"]); 83 os.mkdirp("dir3/");
81 // Check that we get an error if the name is taken by a file. 84 os.system("ls", ["dir3"]);
82 os.system("sh", ["-c", "echo foo > file1"]); 85 // Check that we get an error if the name is taken by a file.
83 os.system("ls", ["file1"]); 86 os.system("sh", ["-c", "echo foo > file1"]);
84 assertThrows("os.mkdirp('file1');", "mkdir over file1"); 87 os.system("ls", ["file1"]);
85 assertThrows("os.mkdirp('file1/foo');", "mkdir over file2"); 88 assertThrows("os.mkdirp('file1');", "mkdir over file1");
86 assertThrows("os.mkdirp('file1/');", "mkdir over file3"); 89 assertThrows("os.mkdirp('file1/foo');", "mkdir over file2");
87 assertThrows("os.mkdirp('file1/foo/');", "mkdir over file4"); 90 assertThrows("os.mkdirp('file1/');", "mkdir over file3");
88 // Create a dir we cannot read. 91 assertThrows("os.mkdirp('file1/foo/');", "mkdir over file4");
89 os.mkdirp("dir4", 0); 92 // Create a dir we cannot read.
90 // This test fails if you are root since root can read any dir. 93 os.mkdirp("dir4", 0);
91 assertThrows("os.chdir('dir4');", "chdir dir4 I"); 94 // This test fails if you are root since root can read any dir.
92 os.rmdir("dir4"); 95 assertThrows("os.chdir('dir4');", "chdir dir4 I");
93 assertThrows("os.chdir('dir4');", "chdir dir4 II"); 96 os.rmdir("dir4");
94 // Set umask. 97 assertThrows("os.chdir('dir4');", "chdir dir4 II");
95 var old_umask = os.umask(0777); 98 // Set umask.
96 // Create a dir we cannot read. 99 var old_umask = os.umask(0777);
97 os.mkdirp("dir5"); 100 // Create a dir we cannot read.
98 // This test fails if you are root since root can read any dir. 101 os.mkdirp("dir5");
99 assertThrows("os.chdir('dir5');", "cd dir5 I"); 102 // This test fails if you are root since root can read any dir.
100 os.rmdir("dir5"); 103 assertThrows("os.chdir('dir5');", "cd dir5 I");
101 assertThrows("os.chdir('dir5');", "chdir dir5 II"); 104 os.rmdir("dir5");
102 os.umask(old_umask); 105 assertThrows("os.chdir('dir5');", "chdir dir5 II");
106 os.umask(old_umask);
103 107
104 os.mkdirp("hest/fisk/../fisk/ged"); 108 os.mkdirp("hest/fisk/../fisk/ged");
105 os.system("ls", ["hest/fisk/ged"]); 109 os.system("ls", ["hest/fisk/ged"]);
106 110
107 os.setenv("FOO", "bar"); 111 os.setenv("FOO", "bar");
108 var environment = os.system("printenv"); 112 var environment = os.system("printenv");
109 assertTrue(/FOO=bar/.test(environment)); 113 assertTrue(/FOO=bar/.test(environment));
110 114
111 // Check we time out. 115 // Check we time out.
112 var have_sleep = true; 116 var have_sleep = true;
113 var have_echo = true; 117 var have_echo = true;
114 try { 118 try {
115 os.system("ls", ["/bin/sleep"]); 119 os.system("ls", ["/bin/sleep"]);
116 } catch (e) { 120 } catch (e) {
117 have_sleep = false; 121 have_sleep = false;
122 }
123 try {
124 os.system("ls", ["/bin/echo"]);
125 } catch (e) {
126 have_echo = false;
127 }
128 if (have_sleep) {
129 assertThrows("os.system('sleep', ['2000'], 200);", "sleep 1");
130
131 // Check we time out with total time.
132 assertThrows("os.system('sleep', ['2000'], -1, 200);", "sleep 2");
133
134 // Check that -1 means no timeout.
135 os.system('sleep', ['1'], -1, -1);
136
137 }
138
139 // Check that we don't fill up the process table with zombies.
140 // Disabled because it's too slow.
141 if (have_echo) {
142 //for (var i = 0; i < 65536; i++) {
143 assertEquals("baz\n", os.system("echo", ["baz"]));
144 //}
145 }
146 } finally {
147 os.chdir("..");
148 os.system("rm", ["-r", TEST_DIR]);
118 } 149 }
119 try {
120 os.system("ls", ["/bin/echo"]);
121 } catch (e) {
122 have_echo = false;
123 }
124 if (have_sleep) {
125 assertThrows("os.system('sleep', ['2000'], 200);", "sleep 1");
126
127 // Check we time out with total time.
128 assertThrows("os.system('sleep', ['2000'], -1, 200);", "sleep 2");
129
130 // Check that -1 means no timeout.
131 os.system('sleep', ['1'], -1, -1);
132
133 }
134
135 // Check that we don't fill up the process table with zombies.
136 // Disabled because it's too slow.
137 if (have_echo) {
138 //for (var i = 0; i < 65536; i++) {
139 assertEquals("baz\n", os.system("echo", ["baz"]));
140 //}
141 }
142
143 os.chdir("..");
144 os.system("rm", ["-r", "d8-os-test-directory"]);
145 150
146 // Too few args. 151 // Too few args.
147 arg_error("os.umask();"); 152 arg_error("os.umask();");
148 arg_error("os.system();"); 153 arg_error("os.system();");
149 arg_error("os.mkdirp();"); 154 arg_error("os.mkdirp();");
150 arg_error("os.chdir();"); 155 arg_error("os.chdir();");
151 arg_error("os.setenv();"); 156 arg_error("os.setenv();");
152 arg_error("os.rmdir();"); 157 arg_error("os.rmdir();");
153 158
154 // Too many args. 159 // Too many args.
(...skipping 16 matching lines...) Expand all
171 str_error("os.system(e);"); 176 str_error("os.system(e);");
172 str_error("os.system('ls', [e]);"); 177 str_error("os.system('ls', [e]);");
173 str_error("os.system('ls', ['.', e]);"); 178 str_error("os.system('ls', ['.', e]);");
174 str_error("os.system('ls', [e, '.']);"); 179 str_error("os.system('ls', [e, '.']);");
175 str_error("os.mkdirp(e);"); 180 str_error("os.mkdirp(e);");
176 str_error("os.setenv(e, 'goo');"); 181 str_error("os.setenv(e, 'goo');");
177 str_error("os.setenv('goo', e);"); 182 str_error("os.setenv('goo', e);");
178 str_error("os.chdir(e);"); 183 str_error("os.chdir(e);");
179 str_error("os.rmdir(e);"); 184 str_error("os.rmdir(e);");
180 } 185 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698