diff options
author | nfullagar@google.com <nfullagar@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-29 02:46:05 +0000 |
---|---|---|
committer | nfullagar@google.com <nfullagar@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-29 02:46:05 +0000 |
commit | 2fca6001b3253cae81487b257e7f465b68da7c5a (patch) | |
tree | 375102868298cfbccd31517e92b73458a1fe93e0 /ppapi/native_client | |
parent | f649ad161832b93524c1e551447720ea1032db54 (diff) | |
download | chromium_src-2fca6001b3253cae81487b257e7f465b68da7c5a.zip chromium_src-2fca6001b3253cae81487b257e7f465b68da7c5a.tar.gz chromium_src-2fca6001b3253cae81487b257e7f465b68da7c5a.tar.bz2 |
Remove NaCl file from ppapi_geturl test.
BUG= none
TEST= ppapi_geturl
Review URL: http://codereview.chromium.org/8589005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@111845 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/native_client')
5 files changed, 3 insertions, 281 deletions
diff --git a/ppapi/native_client/tests/ppapi_geturl/build.scons b/ppapi/native_client/tests/ppapi_geturl/build.scons index 8baaa1c..ca465a8 100644 --- a/ppapi/native_client/tests/ppapi_geturl/build.scons +++ b/ppapi/native_client/tests/ppapi_geturl/build.scons @@ -14,11 +14,6 @@ if env.Bit('linux'): env['COMPONENT_STATIC'] = False # Build a .so, not a .a sources = [ 'module.cc', - # This allow us to verify that the code builds before - # untrusted nacl_file is fully functioning. - # However, main() won't be called when we loaded the trusted - # plugin as a dll. - 'nacl_file_main.cc', 'ppapi_geturl.cc', 'url_load_request.cc' ] diff --git a/ppapi/native_client/tests/ppapi_geturl/module.cc b/ppapi/native_client/tests/ppapi_geturl/module.cc index 04dfef8..766c4b5 100644 --- a/ppapi/native_client/tests/ppapi_geturl/module.cc +++ b/ppapi/native_client/tests/ppapi_geturl/module.cc @@ -13,8 +13,6 @@ #include "native_client/src/include/nacl_macros.h" #include "native_client/src/include/portability.h" #include "native_client/src/shared/platform/nacl_check.h" -#include "native_client/src/untrusted/ppapi/nacl_file.h" -#include "native_client/tests/ppapi_geturl/nacl_file_main.h" #include "native_client/tests/ppapi_geturl/url_load_request.h" #include "ppapi/c/pp_completion_callback.h" @@ -44,53 +42,13 @@ PPP_Instance instance_interface; PPP_Messaging messaging_interface; Module* singleton_ = NULL; -void RunTests(void* user_data) { - int* count = reinterpret_cast<int*>(user_data); - *count -= 1; - if (*count == 0) - test_nacl_file(); -} } // namespace -void HTMLLoaded(void* user_data, int32_t result) { - CHECK(PP_OK == result); - printf("--- HTMLLoaded() SUCCESS: completion callback got PP_OK\n"); - RunTests(user_data); -} - -void RobotLoaded(void* user_data, int32_t result) { - CHECK(PP_ERROR_NOACCESS == result); - printf("--- RobotLoaded() SUCCESS: unable to LoadUrl on cross-domain\n"); - RunTests(user_data); -} - -void NonExistLoaded(void* user_data, int32_t result) { - CHECK(PP_ERROR_FAILED == result); - printf("--- NonExistLoaded() SUCCESS: callback got PP_ERROR_FAILED\n"); - RunTests(user_data); -} - -PP_Bool Instance_DidCreate(PP_Instance pp_instance, +PP_Bool Instance_DidCreate(PP_Instance /*pp_instance*/, uint32_t /*argc*/, const char* /*argn*/[], const char* /*argv*/[]) { printf("--- Instance_DidCreate\n"); - int* url_count = new int(3); - PP_CompletionCallback html_cb = - PP_MakeCompletionCallback(HTMLLoaded, url_count); - int32_t result = LoadUrl(pp_instance, "ppapi_geturl_success.html", html_cb); - CHECK(PP_OK_COMPLETIONPENDING == result); - - PP_CompletionCallback robot_cb = - PP_MakeCompletionCallback(RobotLoaded, url_count); - result = LoadUrl(pp_instance, "http://www.google.com/robots.txt", robot_cb); - CHECK(PP_OK_COMPLETIONPENDING == result); - - PP_CompletionCallback non_exist_cb = - PP_MakeCompletionCallback(NonExistLoaded, url_count); - result = LoadUrl(pp_instance, "ppapi_nonexistent_url.html", non_exist_cb); - CHECK(PP_OK_COMPLETIONPENDING == result); - return PP_TRUE; } diff --git a/ppapi/native_client/tests/ppapi_geturl/nacl.scons b/ppapi/native_client/tests/ppapi_geturl/nacl.scons index d970adf..c6867b1 100644 --- a/ppapi/native_client/tests/ppapi_geturl/nacl.scons +++ b/ppapi/native_client/tests/ppapi_geturl/nacl.scons @@ -12,7 +12,6 @@ # module.h/cc - implementation of PPP_Instance interface # scriptable_object.h/cc - implementation of the scripting interface # url_load_request.h/cc - url loading helper -# nacl_file_main.cc - uses main() to test NaClFile interface Import('env') @@ -29,13 +28,11 @@ env.Alias('ppapi_geturl${PROGSUFFIX}', ['$STAGING_DIR/%s${PROGSUFFIX}' % nexe]) ppapi_geturl_nexe = env.ComponentProgram(nexe, - ['nacl_file_main.cc', - 'module.cc', + ['module.cc', 'ppapi_geturl.cc', 'url_load_request.cc', ], EXTRA_LIBS=[ - 'nacl_file', 'ppruntime', 'srpc', 'imc', @@ -44,11 +41,7 @@ ppapi_geturl_nexe = env.ComponentProgram(nexe, 'gio', '${PTHREAD_LIBS}', 'm', - '${NON_PPAPI_BROWSER_LIBS}'], - EXTRA_LINKFLAGS=['-Wl,--wrap=read', - '-Wl,--wrap=open', - '-Wl,--wrap=lseek', - '-Wl,--wrap=close']) + '${NON_PPAPI_BROWSER_LIBS}']) env.Publish(nexe, 'run', ['ppapi_geturl.html', diff --git a/ppapi/native_client/tests/ppapi_geturl/nacl_file_main.cc b/ppapi/native_client/tests/ppapi_geturl/nacl_file_main.cc index 7562407..e69de29 100644 --- a/ppapi/native_client/tests/ppapi_geturl/nacl_file_main.cc +++ b/ppapi/native_client/tests/ppapi_geturl/nacl_file_main.cc @@ -1,214 +0,0 @@ -// Copyright (c) 2011 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. -// -// Tests nacl_file library. -// - -#include <errno.h> -#include <fcntl.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <pthread.h> -#include <unistd.h> - -#include "native_client/src/include/nacl_base.h" -#include "native_client/src/include/nacl_macros.h" -#include "native_client/src/shared/platform/nacl_check.h" -#include "native_client/src/shared/ppapi_proxy/utility.h" -#include "native_client/src/untrusted/ppapi/nacl_file.h" - -using ppapi_proxy::DebugPrintf; - -struct ThreadInfo { - bool threaded; - unsigned int rseed; -}; - -// Open and read a valid existing file into a buffer. -// Return the number of bytes read. -int test_nacl_file_read_into_buffer(ThreadInfo* info, - int buffer_size, - char* buffer) { - // Valid url should be open and read without errors. - int fd = open("ppapi_geturl_success.html", O_RDONLY); - CHECK(fd >= 0); - int bytes_read = read(fd, buffer, buffer_size); - CHECK(215 == bytes_read); - CHECK(strstr(buffer, "TEST PASSED") == buffer); - close(fd); - if (!info->threaded) { - // This part of the test only works when run in a single thread. In a - // multi-threaded test, between the close (above) and read (below), another - // thread could recycle the fd. In a single threaded test, the read below - // should fail because the fd was just closed. - bytes_read = read(fd, buffer, buffer_size); - CHECK(-1 == bytes_read); - } - return bytes_read; -} - -// Open and read a valid existing file. -void test_nacl_file_basic_read(ThreadInfo* info) { - char buffer[256]; - test_nacl_file_read_into_buffer(info, sizeof(buffer), buffer); -} - -// Do some basic lseek tests on a valid file. -void test_nacl_file_basic_lseek() { - char buffer[256]; - // Some of these seeks are relative, and may depend on results of previous - // seeks. - int fd = open("ppapi_geturl_success.html", O_RDONLY); - CHECK(fd >= 0); - off_t start = lseek(fd, 0, SEEK_SET); - CHECK(0 == start); - off_t end = lseek(fd, 0, SEEK_END); - CHECK(end > 0); - off_t start2 = lseek(fd, -end, SEEK_CUR); - CHECK(0 == start2); - off_t end2 = lseek(fd, end, SEEK_CUR); - CHECK(end2 == end); - off_t end3 = lseek(fd, end, SEEK_SET); - CHECK(end3 == end); - off_t pos1 = lseek(fd, -2, SEEK_CUR); - off_t pos2 = lseek(fd, 0, SEEK_CUR); - CHECK(pos1 == pos2); - lseek(fd, 1, SEEK_CUR); - off_t end4 = lseek(fd, 1, SEEK_CUR); - CHECK(end4 == end); - off_t beyond = lseek(fd, 100, SEEK_END); - CHECK((end + 100) == beyond); - off_t invalid_offset = lseek(fd, -2, SEEK_SET); - CHECK(-1 == invalid_offset); - CHECK(EINVAL == errno); - off_t beyond2 = lseek(fd, 0, SEEK_CUR); - CHECK(beyond2 == beyond); - off_t badfd = lseek(1234567, 0, SEEK_SET); - CHECK(-1 == badfd); - CHECK(EBADF == errno); - // Seek back to start and try same read test again. - CHECK(lseek(fd, 0, SEEK_SET) == 0); - int bytes_read = read(fd, buffer, sizeof(buffer)); - CHECK(215 == bytes_read); - CHECK(strstr(buffer, "TEST PASSED") == buffer); - off_t off = lseek(fd, 0, SEEK_END); - CHECK(215 == off); - close(fd); -} - -// Briefly test the fopen() and friends interface built on top of lower- -// level open() and friends. -void test_nacl_file_fopen() { - FILE* f = fopen("ppapi_geturl_success.html", "r"); - CHECK(NULL != f); - char buffer[256]; - char* pbuffer = fgets(buffer, sizeof(buffer), f); - CHECK(pbuffer == buffer); - fclose(f); - int compare = strcmp(buffer, "TEST PASSED\n"); - CHECK(0 == compare); -} - -// Do a blizzard of small, random file operations. Randomly seek -// and read a byte many times, comparing the read result against the -// whole buffer that was read earlier. Do this against a random number of -// simultaniously temporarily open files. -void test_nacl_file_many_times(ThreadInfo* info) { - int bytes_read; - char buffer[256]; - bytes_read = test_nacl_file_read_into_buffer(info, sizeof(buffer), buffer); - const int kNumOuterLoop = 20; - const int kNumMaxFilesOpen = 10; - const int kNumRandomReads = 500; - for (int i = 0; i < kNumOuterLoop; ++i) { - int file[kNumMaxFilesOpen]; - int num_open = rand_r(&info->rseed) % (kNumMaxFilesOpen - 1) + 1; - CHECK(0 < num_open); - CHECK(kNumMaxFilesOpen > num_open); - for (int j = 0; j < num_open; ++j) { - file[j] = open("ppapi_geturl_success.html", O_RDONLY); - CHECK(-1 != file[j]); - } - int num_reads = rand_r(&info->rseed) % kNumRandomReads; - for (int k = 0; k < num_reads; ++k) { - char a_byte; - const int which_file = rand_r(&info->rseed) % num_open; - const int which_byte = rand_r(&info->rseed) % bytes_read; - int r = lseek(file[which_file], which_byte, SEEK_SET); - CHECK(which_byte == r); - size_t num_read = read(file[which_file], &a_byte, sizeof(a_byte)); - CHECK(1 == num_read); - CHECK(a_byte == buffer[which_byte]); - } - for (int j = 0; j < num_open; ++j) { - close(file[j]); - } - } -} - -// Test nacl_file library functions that override standard POSIX file I/O -// functions and are intended to have the same behavior. -void* test_nacl_file_thread(void* user_data) { - ThreadInfo* info = reinterpret_cast<ThreadInfo*>(user_data); - test_nacl_file_basic_read(info); - test_nacl_file_basic_lseek(); - test_nacl_file_basic_read(info); - // Cross origin url should fail on open. - int fd = open("http://www.google.com/robots.txt", O_RDONLY); - CHECK(-1 == fd); - // Invalid url should fail on open. - fd = open("doesnotexist.html", O_RDONLY); - CHECK(-1 == fd); -#if defined(__native_client__) - // Open for write should fail in NaCl. - int no_fd = open("ppapi_geturl_success.html", O_CREAT); - CHECK(-1 == no_fd); - CHECK(EACCES == errno); -#endif - test_nacl_file_fopen(); - test_nacl_file_many_times(info); - return NULL; -} - -// Main entry point to test nacl_file library. It is assumed that before calling -// this function, LoadUrl() has been invoked for each file to be tested, and -// that the completion callback has been reached. -void test_nacl_file() { - const char *nacl_enable_ppapi_dev = getenv("NACL_ENABLE_PPAPI_DEV"); - int enabled = 0; - // Skip test if NACL_ENABLE_PPAPI_DEV is unset or set to 0. - if (NULL != nacl_enable_ppapi_dev) - enabled = strtol(nacl_enable_ppapi_dev, (char **) 0, 0); - if (enabled == 0) { - DebugPrintf("Skipping NaCl File test, NACL_ENABLE_PPAPI_DEV not set.\n"); - return; - } - const int kNumThreads = 8; - pthread_t thread[kNumThreads]; - ThreadInfo info; - unsigned int rseed = 123456; - info.threaded = false; - info.rseed = rand_r(&rseed); - // Run the test once from the main thread, as the only thread. - test_nacl_file_thread(&info); - info.threaded = true; - // The following test creates threads to test basic file I/O. - // This way we can also ensure that the abstraction is not broken if one - // tries to open/manipulate/close the same NaClFile more then once. - for (int i = 0; i < kNumThreads; ++i) { - info.rseed = rand_r(&rseed); - int p = pthread_create(&thread[i], NULL, test_nacl_file_thread, &info); - CHECK(0 == p); - } - // Run the test from the main thread again, this time competing with - // the other threads. - info.rseed = rand_r(&rseed); - test_nacl_file_thread(&info); - // Give the threads a chance to start racing before joining them. - usleep(100000); - for (int i = 0; i < kNumThreads; ++i) { - pthread_join(thread[i], NULL); - } -} diff --git a/ppapi/native_client/tests/ppapi_geturl/nacl_file_main.h b/ppapi/native_client/tests/ppapi_geturl/nacl_file_main.h index 7ea5f0f..e69de29 100644 --- a/ppapi/native_client/tests/ppapi_geturl/nacl_file_main.h +++ b/ppapi/native_client/tests/ppapi_geturl/nacl_file_main.h @@ -1,10 +0,0 @@ -// Copyright (c) 2011 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. - -#ifndef TESTS_PPAPI_GETURL_NACL_FILE_MAIN_H_ -#define TESTS_PPAPI_GETURL_NACL_FILE_MAIN_H_ - -extern void test_nacl_file(); - -#endif |