Commit 6a40ddad authored by binji@chromium.org's avatar binji@chromium.org

[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
parent 0b701674
...@@ -536,12 +536,12 @@ def GetWindowsEnvironment(): ...@@ -536,12 +536,12 @@ def GetWindowsEnvironment():
return dict(line.split('=') for line in stdout.split('\r\n')[:-1]) return dict(line.split('=') for line in stdout.split('\r\n')[:-1])
def BuildStepBuildLibraries(pepperdir, platform, directory): def BuildStepMakeAll(pepperdir, platform, directory, step_name, clean=False):
buildbot_common.BuildStep('Build Libraries') buildbot_common.BuildStep(step_name)
src_dir = os.path.join(pepperdir, directory) make_dir = os.path.join(pepperdir, directory)
makefile = os.path.join(src_dir, 'Makefile') makefile = os.path.join(make_dir, 'Makefile')
if os.path.isfile(makefile): if os.path.isfile(makefile):
print "\n\nMake: " + src_dir print "\n\nMake: " + make_dir
if platform == 'win': if platform == 'win':
# We need to modify the environment to build host on Windows. # We need to modify the environment to build host on Windows.
env = GetWindowsEnvironment() env = GetWindowsEnvironment()
...@@ -549,10 +549,16 @@ def BuildStepBuildLibraries(pepperdir, platform, directory): ...@@ -549,10 +549,16 @@ def BuildStepBuildLibraries(pepperdir, platform, directory):
env = os.environ env = os.environ
buildbot_common.Run(['make', '-j8'], buildbot_common.Run(['make', '-j8'],
cwd=os.path.abspath(src_dir), shell=True, env=env) cwd=os.path.abspath(make_dir), shell=True, env=env)
if clean:
# Clean to remove temporary files but keep the built libraries. # Clean to remove temporary files but keep the built libraries.
buildbot_common.Run(['make', '-j8', 'clean'], buildbot_common.Run(['make', '-j8', 'clean'],
cwd=os.path.abspath(src_dir), shell=True) cwd=os.path.abspath(make_dir), shell=True)
def BuildStepBuildLibraries(pepperdir, platform, directory):
BuildStepMakeAll(pepperdir, platform, directory, 'Build Libraries',
clean=True)
def BuildStepTarBundle(pepper_ver, tarfile): def BuildStepTarBundle(pepper_ver, tarfile):
...@@ -619,21 +625,11 @@ def BuildStepTestUpdater(platform, pepper_ver, revision, tarfile): ...@@ -619,21 +625,11 @@ def BuildStepTestUpdater(platform, pepper_ver, revision, tarfile):
def BuildStepBuildExamples(pepperdir, platform): def BuildStepBuildExamples(pepperdir, platform):
buildbot_common.BuildStep('Build Examples') BuildStepMakeAll(pepperdir, platform, 'examples', 'Build Examples')
example_dir = os.path.join(pepperdir, 'examples')
makefile = os.path.join(example_dir, 'Makefile')
if os.path.isfile(makefile):
print "\n\nMake: " + example_dir
if platform == 'win':
# We need to modify the environment to build host on Windows.
env = GetWindowsEnvironment()
else:
env = os.environ
buildbot_common.Run(['make', '-j8'],
cwd=os.path.abspath(example_dir), shell=True, env=env)
TEST_EXAMPLE_LIST = [ TEST_EXAMPLE_LIST = [
'nacl_mounts_test',
] ]
TEST_LIBRARY_LIST = [ TEST_LIBRARY_LIST = [
...@@ -651,14 +647,14 @@ def BuildStepCopyTests(pepperdir, toolchains, build_experimental): ...@@ -651,14 +647,14 @@ def BuildStepCopyTests(pepperdir, toolchains, build_experimental):
for toolchain in toolchains: for toolchain in toolchains:
args.append('--' + toolchain) args.append('--' + toolchain)
for example in TEST_EXAMPLE_LIST:
dsc = os.path.join(SDK_EXAMPLE_DIR, example, 'example.dsc')
args.append(dsc)
for library in TEST_LIBRARY_LIST: for library in TEST_LIBRARY_LIST:
dsc = os.path.join(SDK_LIBRARY_DIR, library, 'library.dsc') dsc = os.path.join(SDK_LIBRARY_DIR, library, 'library.dsc')
args.append(dsc) args.append(dsc)
for example in TEST_EXAMPLE_LIST:
dsc = os.path.join(SDK_LIBRARY_DIR, example, 'example.dsc')
args.append(dsc)
if build_experimental: if build_experimental:
args.append('--experimental') args.append('--experimental')
...@@ -666,7 +662,11 @@ def BuildStepCopyTests(pepperdir, toolchains, build_experimental): ...@@ -666,7 +662,11 @@ def BuildStepCopyTests(pepperdir, toolchains, build_experimental):
buildbot_common.ErrorExit('Failed to build tests.') buildbot_common.ErrorExit('Failed to build tests.')
def BuildStepTestExamples(pepperdir, platform, pepper_ver): def BuildStepBuildTests(pepperdir, platform):
BuildStepMakeAll(pepperdir, platform, 'testing', 'Build Tests')
def BuildStepRunPyautoTests(pepperdir, platform, pepper_ver):
buildbot_common.BuildStep('Test Examples') buildbot_common.BuildStep('Test Examples')
env = copy.copy(os.environ) env = copy.copy(os.environ)
env['PEPPER_VER'] = pepper_ver env['PEPPER_VER'] = pepper_ver
...@@ -794,9 +794,9 @@ def main(args): ...@@ -794,9 +794,9 @@ def main(args):
BuildStepBuildLibraries(pepperdir, platform, 'src') BuildStepBuildLibraries(pepperdir, platform, 'src')
BuildStepBuildExamples(pepperdir, platform) BuildStepBuildExamples(pepperdir, platform)
BuildStepCopyTests(pepperdir, toolchains, options.build_experimental) BuildStepCopyTests(pepperdir, toolchains, options.build_experimental)
BuildStepBuildLibraries(pepperdir, platform, 'testing') BuildStepBuildTests(pepperdir, platform)
if options.test_examples: if options.test_examples:
BuildStepTestExamples(pepperdir, platform, pepper_ver) BuildStepRunPyautoTests(pepperdir, platform, pepper_ver)
elif options.only_updater: elif options.only_updater:
build_updater.BuildUpdater(OUT_DIR) build_updater.BuildUpdater(OUT_DIR)
else: # Build everything. else: # Build everything.
...@@ -824,9 +824,9 @@ def main(args): ...@@ -824,9 +824,9 @@ def main(args):
pepperdir = BuildStepTestUpdater(platform, pepper_ver, clnumber, tarfile) pepperdir = BuildStepTestUpdater(platform, pepper_ver, clnumber, tarfile)
BuildStepBuildExamples(pepperdir, platform) BuildStepBuildExamples(pepperdir, platform)
BuildStepCopyTests(pepperdir, toolchains, options.build_experimental) BuildStepCopyTests(pepperdir, toolchains, options.build_experimental)
BuildStepBuildLibraries(pepperdir, platform, 'testing') BuildStepBuildTests(pepperdir, platform)
if options.test_examples: if options.test_examples:
BuildStepTestExamples(pepperdir, platform, pepper_ver) BuildStepRunPyautoTests(pepperdir, platform, pepper_ver)
# Archive on non-trybots. # Archive on non-trybots.
if options.archive or buildbot_common.IsSDKBuilder(): if options.archive or buildbot_common.IsSDKBuilder():
......
...@@ -55,13 +55,13 @@ WIN_CCFLAGS=/I$(NACL_SDK_ROOT)/include /I$(NACL_SDK_ROOT)/include/win -D WIN32 - ...@@ -55,13 +55,13 @@ WIN_CCFLAGS=/I$(NACL_SDK_ROOT)/include /I$(NACL_SDK_ROOT)/include/win -D WIN32 -
# #
CC_RULE = '<tc>/<config>/<name>_<ARCH>.o : %.<ext> $(THIS_MAKE) | <tc>/<config>' CC_RULE = '<tc>/<config>/<name>_<ARCH>.o : %.<ext> $(THIS_MAKE) | <tc>/<config>'
NACL_CC_RULES = { NACL_CC_RULES = {
'Debug': '<TAB>$(<CC>) -o $@ $< -g -O0 <MACH> $(<PROJ>_<EXT>FLAGS) -DTCNAME=<tc> $(<TC>_CCFLAGS) <DEFLIST> <INCLIST>', 'Debug': '<TAB>$(<CC>) -o $@ $< -g -O0 <MACH> -DTCNAME=<tc> $(<TC>_CCFLAGS) $(<PROJ>_<EXT>FLAGS) <DEFLIST> <INCLIST>',
'Release': '<TAB>$(<CC>) -o $@ $< -O2 <MACH> $(<PROJ>_<EXT>FLAGS) -DTCNAME=<tc> $(<TC>_CCFLAGS) <DEFLIST> <INCLIST>', 'Release': '<TAB>$(<CC>) -o $@ $< -O2 <MACH> -DTCNAME=<tc> $(<TC>_CCFLAGS) $(<PROJ>_<EXT>FLAGS) <DEFLIST> <INCLIST>',
} }
SO_CC_RULES = { SO_CC_RULES = {
'Debug': '<TAB>$(<CC>) -o $@ $< -g -O0 <MACH> -fPIC $(<PROJ>_<EXT>FLAGS) -DTCNAME=<tc> $(<TC>_CCFLAGS) <DEFLIST> <INCLIST>', 'Debug': '<TAB>$(<CC>) -o $@ $< -g -O0 <MACH> -fPIC -DTCNAME=<tc> $(<TC>_CCFLAGS) $(<PROJ>_<EXT>FLAGS) <DEFLIST> <INCLIST>',
'Release': '<TAB>$(<CC>) -o $@ $< -02 <MACH> -fPIC $(<PROJ>_<EXT>FLAGS) -DTCNAME=<tc> $(<TC>_CCFLAGS) <DEFLIST> <INCLIST>' 'Release': '<TAB>$(<CC>) -o $@ $< -02 <MACH> -fPIC -DTCNAME=<tc> $(<TC>_CCFLAGS) $(<PROJ>_<EXT>FLAGS) <DEFLIST> <INCLIST>'
} }
WIN_CC_RULES = { WIN_CC_RULES = {
...@@ -73,13 +73,13 @@ WIN_CC_RULES = { ...@@ -73,13 +73,13 @@ WIN_CC_RULES = {
# Link rules for various platforms. # Link rules for various platforms.
# #
NEXE_LINK_RULES = { NEXE_LINK_RULES = {
'Debug': '<TAB>$(<LINK>) -o $@ $^ -g <MACH> $(<PROJ>_LDFLAGS) $(<TC>_LDFLAGS) <LIBLIST>', 'Debug': '<TAB>$(<LINK>) -o $@ $^ -g <MACH> $(<TC>_LDFLAGS) $(<PROJ>_LDFLAGS) -L$(NACL_SDK_ROOT)/lib/$(OSNAME)_<ARCH>_<tc>/<config> <LIBLIST>',
'Release': '<TAB>$(<LINK>) -o $@ $^ <MACH> $(<PROJ>_LDFLAGS) $(<TC>_LDFLAGS) <LIBLIST>' 'Release': '<TAB>$(<LINK>) -o $@ $^ <MACH> $(<TC>_LDFLAGS) $(<PROJ>_LDFLAGS) -L$(NACL_SDK_ROOT)/lib/$(OSNAME)_<ARCH>_<tc>/<config> <LIBLIST>'
} }
SO_LINK_RULES = { SO_LINK_RULES = {
'Debug': '<TAB>$(<LINK>) -o $@ $^ -g <MACH> -shared $(<PROJ>_LDFLAGS) <LIBLIST>', 'Debug': '<TAB>$(<LINK>) -o $@ $^ -g <MACH> -shared $(<PROJ>_LDFLAGS) -L$(NACL_SDK_ROOT)/lib/$(OSNAME)_<ARCH>_<tc>/<config> <LIBLIST>',
'Release': '<TAB>$(<LINK>) -o $@ $^ <MACH> -shared $(<PROJ>_LDFLAGS) <LIBLIST>', 'Release': '<TAB>$(<LINK>) -o $@ $^ <MACH> -shared $(<PROJ>_LDFLAGS) -L$(NACL_SDK_ROOT)/lib/$(OSNAME)_<ARCH>_<tc>/<config> <LIBLIST>',
} }
PEXE_TRANSLATE_RULE = """ PEXE_TRANSLATE_RULE = """
...@@ -93,8 +93,8 @@ PEXE_TRANSLATE_RULE = """ ...@@ -93,8 +93,8 @@ PEXE_TRANSLATE_RULE = """
<TAB>$(TRANSLATE) -arch arm $< -o $@""" <TAB>$(TRANSLATE) -arch arm $< -o $@"""
PEXE_LINK_RULES = { PEXE_LINK_RULES = {
'Debug': '<TAB>$(<LINK>) -o $@ $^ -g $(<PROJ>_LDFLAGS) $(<TC>_LDFLAGS) <LIBLIST>\n' + PEXE_TRANSLATE_RULE, 'Debug': '<TAB>$(<LINK>) -o $@ $^ -g $(<TC>_LDFLAGS) $(<PROJ>_LDFLAGS) -L$(NACL_SDK_ROOT)/lib/$(OSNAME)_<ARCH>_<tc>/<config> <LIBLIST>\n' + PEXE_TRANSLATE_RULE,
'Release': '<TAB>$(<LINK>) -o $@ $^ $(<PROJ>_LDFLAGS) $(<TC>_LDFLAGS) <LIBLIST>\n' + PEXE_TRANSLATE_RULE, 'Release': '<TAB>$(<LINK>) -o $@ $^ $(<TC>_LDFLAGS) $(<PROJ>_LDFLAGS) -L$(NACL_SDK_ROOT)/lib/$(OSNAME)_<ARCH>_<tc>/<config> <LIBLIST>\n' + PEXE_TRANSLATE_RULE,
} }
WIN_LINK_RULES = { WIN_LINK_RULES = {
......
{ {
'TOOLS': ['newlib', 'glibc', 'pnacl', 'win'], 'TOOLS': ['newlib', 'glibc', 'pnacl', 'win'],
'SEARCH': [ 'SEARCH': [
'.',
'../../../../testing/gtest/include/gtest', '../../../../testing/gtest/include/gtest',
'../../../../testing/gtest/include/gtest/internal', '../../../../testing/gtest/include/gtest/internal',
'../../../../testing/gtest/src', '../../../../testing/gtest/src',
...@@ -18,6 +19,7 @@ ...@@ -18,6 +19,7 @@
'gtest-printers.cc', 'gtest-printers.cc',
'gtest-test-part.cc', 'gtest-test-part.cc',
'gtest-typed-test.cc', 'gtest-typed-test.cc',
'nacl_gtest_dummy_sys.cc',
], ],
# Ignore warning: # Ignore warning:
# gtest.cc:2555: error: enumeration value ‘COLOR_DEFAULT’ not handled in switch # gtest.cc:2555: error: enumeration value ‘COLOR_DEFAULT’ not handled in switch
......
// 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"
...@@ -31,7 +31,7 @@ class KernelHandle : public RefObject { ...@@ -31,7 +31,7 @@ class KernelHandle : public RefObject {
friend class KernelObject; friend class KernelObject;
friend class KernelProxy; friend class KernelProxy;
void Acquire() { RefObject::Acquire(); } void Acquire() { RefObject::Acquire(); }
void Release() { RefObject::Release(); } bool Release() { return RefObject::Release(); }
DISALLOW_COPY_AND_ASSIGN(KernelHandle); DISALLOW_COPY_AND_ASSIGN(KernelHandle);
}; };
......
...@@ -71,7 +71,7 @@ class Mount : public RefObject { ...@@ -71,7 +71,7 @@ class Mount : public RefObject {
friend class KernelObject; friend class KernelObject;
friend class KernelProxy; friend class KernelProxy;
void Acquire() { RefObject::Acquire(); } void Acquire() { RefObject::Acquire(); }
void Release() { RefObject::Release(); } bool Release() { return RefObject::Release(); }
template <class M, class P> friend class MountFactory; template <class M, class P> friend class MountFactory;
DISALLOW_COPY_AND_ASSIGN(Mount); DISALLOW_COPY_AND_ASSIGN(Mount);
...@@ -79,10 +79,7 @@ class Mount : public RefObject { ...@@ -79,10 +79,7 @@ class Mount : public RefObject {
template<class C, class P> class MountFactory : public P { template<class C, class P> class MountFactory : public P {
protected: public:
MountFactory()
: P() {}
static Mount* Create(int dev, StringMap_t& args) { static Mount* Create(int dev, StringMap_t& args) {
Mount* mnt = new C(); Mount* mnt = new C();
if (mnt->Init(dev, args) == false) { if (mnt->Init(dev, args) == false) {
...@@ -92,7 +89,8 @@ template<class C, class P> class MountFactory : public P { ...@@ -92,7 +89,8 @@ template<class C, class P> class MountFactory : public P {
return mnt; return mnt;
} }
friend class KernelProxy; protected:
MountFactory(): P() {}
}; };
#endif // LIBRARIES_NACL_MOUNTS_MOUNT_H_ #endif // LIBRARIES_NACL_MOUNTS_MOUNT_H_
{
'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,
}
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include <fcntl.h> #include <fcntl.h>
#include <pthread.h> #include <pthread.h>
#include <unistd.h>
#include <map> #include <map>
#include <string> #include <string>
...@@ -14,7 +13,6 @@ ...@@ -14,7 +13,6 @@
#include "nacl_mounts/kernel_proxy.h" #include "nacl_mounts/kernel_proxy.h"
#include "nacl_mounts/path.h" #include "nacl_mounts/path.h"
#define __STDC__ 1
#include "gtest/gtest.h" #include "gtest/gtest.h"
class KernelProxyMock : public KernelProxy { class KernelProxyMock : public KernelProxy {
...@@ -127,10 +125,12 @@ TEST(KernelIntercept, SanityChecks) { ...@@ -127,10 +125,12 @@ TEST(KernelIntercept, SanityChecks) {
ki_chdir("foo"); ki_chdir("foo");
EXPECT_EQ("chdir", mock->LastStr()); EXPECT_EQ("chdir", mock->LastStr());
ki_getcwd("foo", 1); char getcwd_buffer[] = "foo";
ki_getcwd(getcwd_buffer, 1);
EXPECT_EQ("getcwd", mock->LastStr()); EXPECT_EQ("getcwd", mock->LastStr());
ki_getwd("foo"); char getwd_buffer[] = "foo";
ki_getwd(getwd_buffer);
EXPECT_EQ("getwd", mock->LastStr()); EXPECT_EQ("getwd", mock->LastStr());
ki_dup(1); ki_dup(1);
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include <fcntl.h> #include <fcntl.h>
#include <pthread.h> #include <pthread.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h>
#include <map> #include <map>
#include <string> #include <string>
...@@ -17,7 +16,6 @@ ...@@ -17,7 +16,6 @@
#include "nacl_mounts/mount.h" #include "nacl_mounts/mount.h"
#include "nacl_mounts/path.h" #include "nacl_mounts/path.h"
#define __STDC__ 1
#include "gtest/gtest.h" #include "gtest/gtest.h"
int g_MountCnt = 0; int g_MountCnt = 0;
......
...@@ -6,9 +6,7 @@ ...@@ -6,9 +6,7 @@
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <pthread.h> #include <pthread.h>
#include <sys/mount.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h>
#include <map> #include <map>
#include <string> #include <string>
...@@ -20,7 +18,6 @@ ...@@ -20,7 +18,6 @@
#include "nacl_mounts/mount_mem.h" #include "nacl_mounts/mount_mem.h"
#include "nacl_mounts/path.h" #include "nacl_mounts/path.h"
#define __STDC__ 1
#include "gtest/gtest.h" #include "gtest/gtest.h"
...@@ -30,37 +27,37 @@ TEST(KernelProxy, WorkingDirectory) { ...@@ -30,37 +27,37 @@ TEST(KernelProxy, WorkingDirectory) {
ki_init(new KernelProxy()); ki_init(new KernelProxy());
text[0] = 0; text[0] = 0;
getcwd(text, sizeof(text)); ki_getcwd(text, sizeof(text));
EXPECT_STREQ("/", text); EXPECT_STREQ("/", text);
char* alloc = getwd(NULL); char* alloc = ki_getwd(NULL);
EXPECT_EQ((char *) NULL, alloc); EXPECT_EQ((char *) NULL, alloc);
EXPECT_EQ(EFAULT, errno); EXPECT_EQ(EFAULT, errno);
text[0] = 0; text[0] = 0;
alloc = getwd(text); alloc = ki_getwd(text);
EXPECT_STREQ("/", alloc); EXPECT_STREQ("/", alloc);
EXPECT_EQ(-1, chdir("/foo")); EXPECT_EQ(-1, ki_chdir("/foo"));
EXPECT_EQ(EEXIST, errno); EXPECT_EQ(EEXIST, errno);
EXPECT_EQ(0, chdir("/")); EXPECT_EQ(0, ki_chdir("/"));
EXPECT_EQ(0, mkdir("/foo", S_IREAD | S_IWRITE)); EXPECT_EQ(0, ki_mkdir("/foo", S_IREAD | S_IWRITE));
EXPECT_EQ(-1, mkdir("/foo", S_IREAD | S_IWRITE)); EXPECT_EQ(-1, ki_mkdir("/foo", S_IREAD | S_IWRITE));
EXPECT_EQ(EEXIST, errno); EXPECT_EQ(EEXIST, errno);
memset(text, 0, sizeof(text)); memset(text, 0, sizeof(text));
EXPECT_EQ(0, chdir("foo")); EXPECT_EQ(0, ki_chdir("foo"));
EXPECT_EQ(text, getcwd(text, sizeof(text))); EXPECT_EQ(text, ki_getcwd(text, sizeof(text)));
EXPECT_STREQ("/foo", text); EXPECT_STREQ("/foo", text);
memset(text, 0, sizeof(text)); memset(text, 0, sizeof(text));
EXPECT_EQ(-1, chdir("foo")); EXPECT_EQ(-1, ki_chdir("foo"));
EXPECT_EQ(EEXIST, errno); EXPECT_EQ(EEXIST, errno);
EXPECT_EQ(0, chdir("..")); EXPECT_EQ(0, ki_chdir(".."));
EXPECT_EQ(0, chdir("/foo")); EXPECT_EQ(0, ki_chdir("/foo"));
EXPECT_EQ(text, getcwd(text, sizeof(text))); EXPECT_EQ(text, ki_getcwd(text, sizeof(text)));
EXPECT_STREQ("/foo", text); EXPECT_STREQ("/foo", text);
} }
...@@ -72,52 +69,52 @@ TEST(KernelProxy, MemMountIO) { ...@@ -72,52 +69,52 @@ TEST(KernelProxy, MemMountIO) {
ki_init(new KernelProxy()); ki_init(new KernelProxy());
// Create "/foo" // 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" // 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); EXPECT_EQ(ENOENT, errno);
// Create bar "/foo/bar" // 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); EXPECT_NE(-1, fd1);
// Open (optionally create) bar "/foo/bar" // 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); EXPECT_NE(-1, fd2);
// Fail to exclusively create bar "/foo/bar" // 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); EXPECT_EQ(EEXIST, errno);
// Write hello and world to same node with different descriptors // Write hello and world to same node with different descriptors
// so that we overwrite each other // so that we overwrite each other
EXPECT_EQ(5, write(fd2, "WORLD", 5)); EXPECT_EQ(5, ki_write(fd2, "WORLD", 5));
EXPECT_EQ(5, write(fd1, "HELLO", 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); EXPECT_NE(-1, fd3);
len = read(fd3, text, sizeof(text)); len = ki_read(fd3, text, sizeof(text));
if (len > -0) text[len] = 0; if (len > -0) text[len] = 0;
EXPECT_EQ(5, len); EXPECT_EQ(5, len);
EXPECT_STREQ("HELLO", text); EXPECT_STREQ("HELLO", text);
EXPECT_EQ(0, close(fd1)); EXPECT_EQ(0, ki_close(fd1));
EXPECT_EQ(0, close(fd2)); 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_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; if (len >= 0) text[len] = 0;
EXPECT_EQ(5, len); EXPECT_EQ(5, len);
EXPECT_STREQ("WORLD", text); EXPECT_STREQ("WORLD", text);
fd2 = open("/foo/bar", O_RDONLY); fd2 = ki_open("/foo/bar", O_RDONLY);
EXPECT_NE(-1, fd2); EXPECT_NE(-1, fd2);
len = read(fd2, text, sizeof(text)); len = ki_read(fd2, text, sizeof(text));
if (len > 0) text[len] = 0; if (len > 0) text[len] = 0;
EXPECT_EQ(10, len); EXPECT_EQ(10, len);
EXPECT_STREQ("HELLOWORLD", text); EXPECT_STREQ("HELLOWORLD", text);
...@@ -144,13 +141,13 @@ class KernelProxyMountMock : public KernelProxy { ...@@ -144,13 +141,13 @@ class KernelProxyMountMock : public KernelProxy {
TEST(KernelProxy, MountInit) { TEST(KernelProxy, MountInit) {
ki_init(new KernelProxyMountMock()); 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("bar", g_StringMap["foo"]);
EXPECT_EQ(-1, res1); EXPECT_EQ(-1, res1);
EXPECT_EQ(EINVAL, errno); 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_NE(-1, res2);
EXPECT_EQ("y", g_StringMap["x"]); EXPECT_EQ("y", g_StringMap["x"]);
} }
...@@ -5,14 +5,13 @@ ...@@ -5,14 +5,13 @@
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h>
#include "nacl_mounts/kernel_proxy.h" #include "nacl_mounts/kernel_proxy.h"
#include "nacl_mounts/mount_node.h" #include "nacl_mounts/mount_node.h"
#include "nacl_mounts/mount_node_dir.h" #include "nacl_mounts/mount_node_dir.h"
#include "nacl_mounts/mount_node_mem.h" #include "nacl_mounts/mount_node_mem.h"
#include "nacl_mounts/osdirent.h"
#define __STDC__ 1
#include "gtest/gtest.h" #include "gtest/gtest.h"
#define NULL_NODE ((MountNode *) NULL) #define NULL_NODE ((MountNode *) NULL)
...@@ -79,7 +78,7 @@ TEST(MountNodeTest, File) { ...@@ -79,7 +78,7 @@ TEST(MountNodeTest, File) {
// Test properties // Test properties
EXPECT_EQ(0, file->GetLinks()); EXPECT_EQ(0, file->GetLinks());
EXPECT_EQ(S_IREAD | S_IWRITE, file->GetMode()); 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(false, file->IsaDir());
EXPECT_EQ(true, file->IsaFile()); EXPECT_EQ(true, file->IsaFile());
EXPECT_EQ(false, file->IsaTTY()); EXPECT_EQ(false, file->IsaTTY());
...@@ -88,7 +87,7 @@ TEST(MountNodeTest, File) { ...@@ -88,7 +87,7 @@ TEST(MountNodeTest, File) {
// Test IO // Test IO
char buf1[1024]; char buf1[1024];
char buf2[1024 * 2]; char buf2[1024 * 2];
for (int a=0; a < sizeof(buf1); a++) for (size_t a = 0; a < sizeof(buf1); a++)
buf1[a] = a; buf1[a] = a;
memset(buf2, 0, sizeof(buf2)); memset(buf2, 0, sizeof(buf2));
...@@ -125,7 +124,7 @@ TEST(MountNodeTest, Directory) { ...@@ -125,7 +124,7 @@ TEST(MountNodeTest, Directory) {
// Test properties // Test properties
EXPECT_EQ(0, root->GetLinks()); EXPECT_EQ(0, root->GetLinks());
EXPECT_EQ(S_IREAD | S_IWRITE, root->GetMode()); 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(true, root->IsaDir());
EXPECT_EQ(false, root->IsaFile()); EXPECT_EQ(false, root->IsaFile());
EXPECT_EQ(false, root->IsaTTY()); EXPECT_EQ(false, root->IsaTTY());
......
...@@ -3,18 +3,16 @@ ...@@ -3,18 +3,16 @@
* found in the LICENSE file. * found in the LICENSE file.
*/ */
#include <dirent.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <string> #include <string>
#include "nacl_mounts/mount.h" #include "nacl_mounts/mount.h"
#include "nacl_mounts/mount_mem.h" #include "nacl_mounts/mount_mem.h"
#include "nacl_mounts/osdirent.h"
#define __STDC__ 1
#include "gtest/gtest.h" #include "gtest/gtest.h"
class MountMock : public MountMem { class MountMock : public MountMem {
......
...@@ -4,11 +4,9 @@ ...@@ -4,11 +4,9 @@
*/ */
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h>
#include "nacl_mounts/kernel_proxy.h" #include "nacl_mounts/kernel_proxy.h"
#include "nacl_mounts/path.h" #include "nacl_mounts/path.h"
#define __STDC__ 1
#include "gtest/gtest.h" #include "gtest/gtest.h"
TEST(PathTest, SanityChecks) { TEST(PathTest, SanityChecks) {
......
...@@ -21,10 +21,12 @@ class RefObject { ...@@ -21,10 +21,12 @@ class RefObject {
void Acquire() { void Acquire() {
ref_count_++; ref_count_++;
} }
void Release() { bool Release() {
if (--ref_count_ == 0) { if (--ref_count_ == 0) {
delete this; delete this;
return false;
} }
return true;
} }
protected: protected:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment