forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Android: Refactor native test setup in a util class.
This is also needed by content_browsertests. Also redirecting stdout,stderr for content_browsertests to a fifo file to be read by the test runner scripts. BUG=138275 TBR=jam@chromium.org Review URL: https://chromiumcodereview.appspot.com/12213035 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@181587 0039d316-1c4b-4281-b951-d872f2087c98
- Loading branch information
nileshagrawal@chromium.org
committed
Feb 9, 2013
1 parent
c5e5790
commit 06078a2
Showing
6 changed files
with
179 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// Copyright (c) 2013 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. | ||
|
||
#include "testing/android/native_test_util.h" | ||
|
||
#include <android/log.h> | ||
#include <stdarg.h> | ||
#include <stdio.h> | ||
#include <sys/types.h> | ||
#include <sys/stat.h> | ||
#include <unistd.h> | ||
|
||
#include "base/command_line.h" | ||
#include "base/file_path.h" | ||
#include "base/file_util.h" | ||
#include "base/string_util.h" | ||
#include "base/strings/string_tokenizer.h" | ||
|
||
namespace { | ||
|
||
const char kLogTag[] = "chromium"; | ||
|
||
void AndroidLogError(const char* format, ...) { | ||
va_list args; | ||
va_start(args, format); | ||
__android_log_vprint(ANDROID_LOG_ERROR, kLogTag, format, args); | ||
va_end(args); | ||
} | ||
|
||
void ParseArgsFromString(const std::string& command_line, | ||
std::vector<std::string>* args) { | ||
base::StringTokenizer tokenizer(command_line, kWhitespaceASCII); | ||
tokenizer.set_quote_chars("\""); | ||
while (tokenizer.GetNext()) { | ||
std::string token; | ||
RemoveChars(tokenizer.token(), "\"", &token); | ||
args->push_back(token); | ||
} | ||
} | ||
|
||
} // namespace | ||
|
||
namespace testing { | ||
namespace native_test_util { | ||
|
||
void CreateFIFO(const char* fifo_path) { | ||
unlink(fifo_path); | ||
// Default permissions for mkfifo is ignored, chmod is required. | ||
if (mkfifo(fifo_path, 0666) || chmod(fifo_path, 0666)) { | ||
AndroidLogError("Failed to create fifo %s: %s\n", | ||
fifo_path, strerror(errno)); | ||
exit(EXIT_FAILURE); | ||
} | ||
} | ||
|
||
void RedirectStream( | ||
FILE* stream, const char* path, const char* mode) { | ||
if (!freopen(path, mode, stream)) { | ||
AndroidLogError("Failed to redirect stream to file: %s: %s\n", | ||
path, strerror(errno)); | ||
exit(EXIT_FAILURE); | ||
} | ||
} | ||
|
||
void ParseArgsFromCommandLineFile( | ||
const char* path, std::vector<std::string>* args) { | ||
base::FilePath command_line(path); | ||
std::string command_line_string; | ||
if (file_util::ReadFileToString(command_line, &command_line_string)) { | ||
ParseArgsFromString(command_line_string, args); | ||
} | ||
} | ||
|
||
int ArgsToArgv(const std::vector<std::string>& args, | ||
std::vector<char*>* argv) { | ||
// We need to pass in a non-const char**. | ||
int argc = args.size(); | ||
|
||
argv->resize(argc + 1); | ||
for (int i = 0; i < argc; ++i) { | ||
(*argv)[i] = const_cast<char*>(args[i].c_str()); | ||
} | ||
(*argv)[argc] = NULL; // argv must be NULL terminated. | ||
|
||
return argc; | ||
} | ||
|
||
} // namespace native_test_util | ||
} // namespace testing |
Oops, something went wrong.