diff options
author | binji@chromium.org <binji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-09 20:40:23 +0000 |
---|---|---|
committer | binji@chromium.org <binji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-09 20:40:23 +0000 |
commit | 6a40ddad00cc5c1a329c39605633c818782b84ad (patch) | |
tree | fb38e1ef89ba4ba387b136dba0b5c317aaf6efac /native_client_sdk/src/libraries | |
parent | 0b7016747ea862405f2062d493d01ff8a6dae3c4 (diff) | |
download | chromium_src-6a40ddad00cc5c1a329c39605633c818782b84ad.zip chromium_src-6a40ddad00cc5c1a329c39605633c818782b84ad.tar.gz chromium_src-6a40ddad00cc5c1a329c39605633c818782b84ad.tar.bz2 |
[NaCl SDK] Get nacl_mounts_tests building.
BUG=none
NOTRY=true
Review URL: https://chromiumcodereview.appspot.com/10825189
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@150893 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'native_client_sdk/src/libraries')
12 files changed, 109 insertions, 59 deletions
diff --git a/native_client_sdk/src/libraries/gtest/library.dsc b/native_client_sdk/src/libraries/gtest/library.dsc index a7405a8..ee5e87c 100644 --- a/native_client_sdk/src/libraries/gtest/library.dsc +++ b/native_client_sdk/src/libraries/gtest/library.dsc @@ -1,6 +1,7 @@ { 'TOOLS': ['newlib', 'glibc', 'pnacl', 'win'], 'SEARCH': [ + '.', '../../../../testing/gtest/include/gtest', '../../../../testing/gtest/include/gtest/internal', '../../../../testing/gtest/src', @@ -18,6 +19,7 @@ 'gtest-printers.cc', 'gtest-test-part.cc', 'gtest-typed-test.cc', + 'nacl_gtest_dummy_sys.cc', ], # Ignore warning: # gtest.cc:2555: error: enumeration value ‘COLOR_DEFAULT’ not handled in switch diff --git a/native_client_sdk/src/libraries/gtest/nacl_gtest_dummy_sys.cc b/native_client_sdk/src/libraries/gtest/nacl_gtest_dummy_sys.cc new file mode 100644 index 0000000..ef7cf61 --- /dev/null +++ b/native_client_sdk/src/libraries/gtest/nacl_gtest_dummy_sys.cc @@ -0,0 +1,36 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#if defined(__native_client__) +#include <errno.h> +#include <string.h> +#include <sys/types.h> +#endif + +extern "C" { + +#if defined(__native_client__) + +char* getcwd(char* buf, size_t size) { + if (size < 2) { + errno = ERANGE; + return NULL; + } + + return strncpy(buf, ".", size); +} + +int unlink(const char* pathname) { + errno = ENOSYS; + return -1; +} + +int mkdir(const char* pathname, mode_t mode) { + errno = ENOSYS; + return -1; +} + +#endif + +} // extern "C" diff --git a/native_client_sdk/src/libraries/nacl_mounts/kernel_handle.h b/native_client_sdk/src/libraries/nacl_mounts/kernel_handle.h index 141a788..4c11606 100644 --- a/native_client_sdk/src/libraries/nacl_mounts/kernel_handle.h +++ b/native_client_sdk/src/libraries/nacl_mounts/kernel_handle.h @@ -31,7 +31,7 @@ class KernelHandle : public RefObject { friend class KernelObject; friend class KernelProxy; void Acquire() { RefObject::Acquire(); } - void Release() { RefObject::Release(); } + bool Release() { return RefObject::Release(); } DISALLOW_COPY_AND_ASSIGN(KernelHandle); }; diff --git a/native_client_sdk/src/libraries/nacl_mounts/mount.h b/native_client_sdk/src/libraries/nacl_mounts/mount.h index cbb8014..53d160a 100644 --- a/native_client_sdk/src/libraries/nacl_mounts/mount.h +++ b/native_client_sdk/src/libraries/nacl_mounts/mount.h @@ -71,7 +71,7 @@ class Mount : public RefObject { friend class KernelObject; friend class KernelProxy; void Acquire() { RefObject::Acquire(); } - void Release() { RefObject::Release(); } + bool Release() { return RefObject::Release(); } template <class M, class P> friend class MountFactory; DISALLOW_COPY_AND_ASSIGN(Mount); @@ -79,10 +79,7 @@ class Mount : public RefObject { template<class C, class P> class MountFactory : public P { - protected: - MountFactory() - : P() {} - + public: static Mount* Create(int dev, StringMap_t& args) { Mount* mnt = new C(); if (mnt->Init(dev, args) == false) { @@ -92,7 +89,8 @@ template<class C, class P> class MountFactory : public P { return mnt; } - friend class KernelProxy; + protected: + MountFactory(): P() {} }; #endif // LIBRARIES_NACL_MOUNTS_MOUNT_H_ diff --git a/native_client_sdk/src/libraries/nacl_mounts_test/example.dsc b/native_client_sdk/src/libraries/nacl_mounts_test/example.dsc new file mode 100644 index 0000000..7db3e8d --- /dev/null +++ b/native_client_sdk/src/libraries/nacl_mounts_test/example.dsc @@ -0,0 +1,22 @@ +{ + 'TOOLS': ['newlib', 'glibc', 'pnacl', 'win'], + 'TARGETS': [ + { + 'NAME' : 'nacl_mounts_test', + 'TYPE' : 'main', + 'SOURCES' : [ + 'kernel_intercept_test.cc', + 'kernel_object_test.cc', + 'kernel_proxy_test.cc', + 'mount_node_test.cc', + 'mount_test.cc', + 'path_test.cc', + 'test.cc', + ], + 'LIBS': ['ppapi', 'pthread', 'gtest', 'nacl_mounts'] + } + ], + 'DEST': 'testing', + 'NAME': 'nacl_mounts_test', + 'EXPERIMENTAL': True, +} diff --git a/native_client_sdk/src/libraries/nacl_mounts_test/kernel_intercept_test.cc b/native_client_sdk/src/libraries/nacl_mounts_test/kernel_intercept_test.cc index dc0c0fc..494db2f 100644 --- a/native_client_sdk/src/libraries/nacl_mounts_test/kernel_intercept_test.cc +++ b/native_client_sdk/src/libraries/nacl_mounts_test/kernel_intercept_test.cc @@ -5,7 +5,6 @@ #include <fcntl.h> #include <pthread.h> -#include <unistd.h> #include <map> #include <string> @@ -14,7 +13,6 @@ #include "nacl_mounts/kernel_proxy.h" #include "nacl_mounts/path.h" -#define __STDC__ 1 #include "gtest/gtest.h" class KernelProxyMock : public KernelProxy { @@ -127,10 +125,12 @@ TEST(KernelIntercept, SanityChecks) { ki_chdir("foo"); EXPECT_EQ("chdir", mock->LastStr()); - ki_getcwd("foo", 1); + char getcwd_buffer[] = "foo"; + ki_getcwd(getcwd_buffer, 1); EXPECT_EQ("getcwd", mock->LastStr()); - ki_getwd("foo"); + char getwd_buffer[] = "foo"; + ki_getwd(getwd_buffer); EXPECT_EQ("getwd", mock->LastStr()); ki_dup(1); diff --git a/native_client_sdk/src/libraries/nacl_mounts_test/kernel_object_test.cc b/native_client_sdk/src/libraries/nacl_mounts_test/kernel_object_test.cc index 0c0519e..5854921 100644 --- a/native_client_sdk/src/libraries/nacl_mounts_test/kernel_object_test.cc +++ b/native_client_sdk/src/libraries/nacl_mounts_test/kernel_object_test.cc @@ -7,7 +7,6 @@ #include <fcntl.h> #include <pthread.h> #include <sys/stat.h> -#include <unistd.h> #include <map> #include <string> @@ -17,7 +16,6 @@ #include "nacl_mounts/mount.h" #include "nacl_mounts/path.h" -#define __STDC__ 1 #include "gtest/gtest.h" int g_MountCnt = 0; diff --git a/native_client_sdk/src/libraries/nacl_mounts_test/kernel_proxy_test.cc b/native_client_sdk/src/libraries/nacl_mounts_test/kernel_proxy_test.cc index 67a207d..e048e12 100644 --- a/native_client_sdk/src/libraries/nacl_mounts_test/kernel_proxy_test.cc +++ b/native_client_sdk/src/libraries/nacl_mounts_test/kernel_proxy_test.cc @@ -6,9 +6,7 @@ #include <errno.h> #include <fcntl.h> #include <pthread.h> -#include <sys/mount.h> #include <sys/stat.h> -#include <unistd.h> #include <map> #include <string> @@ -20,7 +18,6 @@ #include "nacl_mounts/mount_mem.h" #include "nacl_mounts/path.h" -#define __STDC__ 1 #include "gtest/gtest.h" @@ -30,37 +27,37 @@ TEST(KernelProxy, WorkingDirectory) { ki_init(new KernelProxy()); text[0] = 0; - getcwd(text, sizeof(text)); + ki_getcwd(text, sizeof(text)); EXPECT_STREQ("/", text); - char* alloc = getwd(NULL); + char* alloc = ki_getwd(NULL); EXPECT_EQ((char *) NULL, alloc); EXPECT_EQ(EFAULT, errno); text[0] = 0; - alloc = getwd(text); + alloc = ki_getwd(text); EXPECT_STREQ("/", alloc); - EXPECT_EQ(-1, chdir("/foo")); + EXPECT_EQ(-1, ki_chdir("/foo")); EXPECT_EQ(EEXIST, errno); - EXPECT_EQ(0, chdir("/")); + EXPECT_EQ(0, ki_chdir("/")); - EXPECT_EQ(0, mkdir("/foo", S_IREAD | S_IWRITE)); - EXPECT_EQ(-1, mkdir("/foo", S_IREAD | S_IWRITE)); + EXPECT_EQ(0, ki_mkdir("/foo", S_IREAD | S_IWRITE)); + EXPECT_EQ(-1, ki_mkdir("/foo", S_IREAD | S_IWRITE)); EXPECT_EQ(EEXIST, errno); memset(text, 0, sizeof(text)); - EXPECT_EQ(0, chdir("foo")); - EXPECT_EQ(text, getcwd(text, sizeof(text))); + EXPECT_EQ(0, ki_chdir("foo")); + EXPECT_EQ(text, ki_getcwd(text, sizeof(text))); EXPECT_STREQ("/foo", text); memset(text, 0, sizeof(text)); - EXPECT_EQ(-1, chdir("foo")); + EXPECT_EQ(-1, ki_chdir("foo")); EXPECT_EQ(EEXIST, errno); - EXPECT_EQ(0, chdir("..")); - EXPECT_EQ(0, chdir("/foo")); - EXPECT_EQ(text, getcwd(text, sizeof(text))); + EXPECT_EQ(0, ki_chdir("..")); + EXPECT_EQ(0, ki_chdir("/foo")); + EXPECT_EQ(text, ki_getcwd(text, sizeof(text))); EXPECT_STREQ("/foo", text); } @@ -72,52 +69,52 @@ TEST(KernelProxy, MemMountIO) { ki_init(new KernelProxy()); // Create "/foo" - EXPECT_EQ(0, mkdir("/foo", S_IREAD | S_IWRITE)); + EXPECT_EQ(0, ki_mkdir("/foo", S_IREAD | S_IWRITE)); // Fail to open "/foo/bar" - EXPECT_EQ(-1, open("/foo/bar", O_RDONLY)); + EXPECT_EQ(-1, ki_open("/foo/bar", O_RDONLY)); EXPECT_EQ(ENOENT, errno); // Create bar "/foo/bar" - fd1 = open("/foo/bar", O_RDONLY | O_CREAT); + fd1 = ki_open("/foo/bar", O_RDONLY | O_CREAT); EXPECT_NE(-1, fd1); // Open (optionally create) bar "/foo/bar" - fd2 = open("/foo/bar", O_RDONLY | O_CREAT); + fd2 = ki_open("/foo/bar", O_RDONLY | O_CREAT); EXPECT_NE(-1, fd2); // Fail to exclusively create bar "/foo/bar" - EXPECT_EQ(-1, open("/foo/bar", O_RDONLY | O_CREAT | O_EXCL)); + EXPECT_EQ(-1, ki_open("/foo/bar", O_RDONLY | O_CREAT | O_EXCL)); EXPECT_EQ(EEXIST, errno); // Write hello and world to same node with different descriptors // so that we overwrite each other - EXPECT_EQ(5, write(fd2, "WORLD", 5)); - EXPECT_EQ(5, write(fd1, "HELLO", 5)); + EXPECT_EQ(5, ki_write(fd2, "WORLD", 5)); + EXPECT_EQ(5, ki_write(fd1, "HELLO", 5)); - fd3 = open("/foo/bar", O_WRONLY); + fd3 = ki_open("/foo/bar", O_WRONLY); EXPECT_NE(-1, fd3); - len = read(fd3, text, sizeof(text)); + len = ki_read(fd3, text, sizeof(text)); if (len > -0) text[len] = 0; EXPECT_EQ(5, len); EXPECT_STREQ("HELLO", text); - EXPECT_EQ(0, close(fd1)); - EXPECT_EQ(0, close(fd2)); + EXPECT_EQ(0, ki_close(fd1)); + EXPECT_EQ(0, ki_close(fd2)); - fd1 = open("/foo/bar", O_WRONLY | O_APPEND); + fd1 = ki_open("/foo/bar", O_WRONLY | O_APPEND); EXPECT_NE(-1, fd1); - EXPECT_EQ(5, write(fd1, "WORLD", 5)); + EXPECT_EQ(5, ki_write(fd1, "WORLD", 5)); - len = read(fd3, text, sizeof(text)); + len = ki_read(fd3, text, sizeof(text)); if (len >= 0) text[len] = 0; EXPECT_EQ(5, len); EXPECT_STREQ("WORLD", text); - fd2 = open("/foo/bar", O_RDONLY); + fd2 = ki_open("/foo/bar", O_RDONLY); EXPECT_NE(-1, fd2); - len = read(fd2, text, sizeof(text)); + len = ki_read(fd2, text, sizeof(text)); if (len > 0) text[len] = 0; EXPECT_EQ(10, len); EXPECT_STREQ("HELLOWORLD", text); @@ -144,13 +141,13 @@ class KernelProxyMountMock : public KernelProxy { TEST(KernelProxy, MountInit) { ki_init(new KernelProxyMountMock()); - int res1 = mount("/", "/mnt1", "initfs", 0, "false,foo=bar"); + int res1 = ki_mount("/", "/mnt1", "initfs", 0, "false,foo=bar"); EXPECT_EQ("bar", g_StringMap["foo"]); EXPECT_EQ(-1, res1); EXPECT_EQ(EINVAL, errno); - int res2 = mount("/", "/mnt2", "initfs", 0, "true,bar=foo,x=y"); + int res2 = ki_mount("/", "/mnt2", "initfs", 0, "true,bar=foo,x=y"); EXPECT_NE(-1, res2); EXPECT_EQ("y", g_StringMap["x"]); -}
\ No newline at end of file +} diff --git a/native_client_sdk/src/libraries/nacl_mounts_test/mount_node_test.cc b/native_client_sdk/src/libraries/nacl_mounts_test/mount_node_test.cc index e38b1fe..3994b9d 100644 --- a/native_client_sdk/src/libraries/nacl_mounts_test/mount_node_test.cc +++ b/native_client_sdk/src/libraries/nacl_mounts_test/mount_node_test.cc @@ -5,14 +5,13 @@ #include <errno.h> #include <fcntl.h> -#include <unistd.h> #include "nacl_mounts/kernel_proxy.h" #include "nacl_mounts/mount_node.h" #include "nacl_mounts/mount_node_dir.h" #include "nacl_mounts/mount_node_mem.h" +#include "nacl_mounts/osdirent.h" -#define __STDC__ 1 #include "gtest/gtest.h" #define NULL_NODE ((MountNode *) NULL) @@ -79,7 +78,7 @@ TEST(MountNodeTest, File) { // Test properties EXPECT_EQ(0, file->GetLinks()); EXPECT_EQ(S_IREAD | S_IWRITE, file->GetMode()); - EXPECT_EQ(_S_IFREG, file->GetType()); + EXPECT_EQ(S_IFREG, file->GetType()); EXPECT_EQ(false, file->IsaDir()); EXPECT_EQ(true, file->IsaFile()); EXPECT_EQ(false, file->IsaTTY()); @@ -88,7 +87,7 @@ TEST(MountNodeTest, File) { // Test IO char buf1[1024]; char buf2[1024 * 2]; - for (int a=0; a < sizeof(buf1); a++) + for (size_t a = 0; a < sizeof(buf1); a++) buf1[a] = a; memset(buf2, 0, sizeof(buf2)); @@ -125,7 +124,7 @@ TEST(MountNodeTest, Directory) { // Test properties EXPECT_EQ(0, root->GetLinks()); EXPECT_EQ(S_IREAD | S_IWRITE, root->GetMode()); - EXPECT_EQ(_S_IFDIR, root->GetType()); + EXPECT_EQ(S_IFDIR, root->GetType()); EXPECT_EQ(true, root->IsaDir()); EXPECT_EQ(false, root->IsaFile()); EXPECT_EQ(false, root->IsaTTY()); diff --git a/native_client_sdk/src/libraries/nacl_mounts_test/mount_test.cc b/native_client_sdk/src/libraries/nacl_mounts_test/mount_test.cc index c5f2537..f649c2a 100644 --- a/native_client_sdk/src/libraries/nacl_mounts_test/mount_test.cc +++ b/native_client_sdk/src/libraries/nacl_mounts_test/mount_test.cc @@ -3,18 +3,16 @@ * found in the LICENSE file. */ -#include <dirent.h> #include <errno.h> #include <fcntl.h> -#include <unistd.h> #include <sys/stat.h> #include <string> #include "nacl_mounts/mount.h" #include "nacl_mounts/mount_mem.h" +#include "nacl_mounts/osdirent.h" -#define __STDC__ 1 #include "gtest/gtest.h" class MountMock : public MountMem { diff --git a/native_client_sdk/src/libraries/nacl_mounts_test/path_test.cc b/native_client_sdk/src/libraries/nacl_mounts_test/path_test.cc index 4e3caaa..44176f3 100644 --- a/native_client_sdk/src/libraries/nacl_mounts_test/path_test.cc +++ b/native_client_sdk/src/libraries/nacl_mounts_test/path_test.cc @@ -4,11 +4,9 @@ */ #include <fcntl.h> -#include <unistd.h> #include "nacl_mounts/kernel_proxy.h" #include "nacl_mounts/path.h" -#define __STDC__ 1 #include "gtest/gtest.h" TEST(PathTest, SanityChecks) { diff --git a/native_client_sdk/src/libraries/utils/ref_object.h b/native_client_sdk/src/libraries/utils/ref_object.h index cfee3a6..6cd8c84 100644 --- a/native_client_sdk/src/libraries/utils/ref_object.h +++ b/native_client_sdk/src/libraries/utils/ref_object.h @@ -21,10 +21,12 @@ class RefObject { void Acquire() { ref_count_++; } - void Release() { + bool Release() { if (--ref_count_ == 0) { delete this; + return false; } + return true; } protected: |