Fuchsia: Use low-level prng call, add test, update test runner.

There is now a syscall for getting cryptographically secure random bytes.

R=asiva@google.com

Review URL: https://codereview.chromium.org/2204523002 .
This commit is contained in:
Zachary Anderson 2016-08-02 13:18:37 -07:00
parent 081718c198
commit e476e00ca6
7 changed files with 68 additions and 13 deletions

View file

@ -13,6 +13,7 @@
'crypto_fuchsia.cc',
'crypto_linux.cc',
'crypto_macos.cc',
'crypto_test.cc',
'crypto_win.cc',
'builtin_common.cc',
'dartutils.cc',

View file

@ -7,20 +7,23 @@
#include "bin/crypto.h"
#include <magenta/syscalls.h>
namespace dart {
namespace bin {
bool Crypto::GetRandomBytes(intptr_t count, uint8_t* buffer) {
uint32_t num;
intptr_t read = 0;
while (read < count) {
if (rand_r(&num) != 0) {
const intptr_t remaining = count - read;
const intptr_t len =
(MX_CPRNG_DRAW_MAX_LEN < remaining) ? MX_CPRNG_DRAW_MAX_LEN
: remaining;
const mx_ssize_t res = mx_cprng_draw(buffer + read, len);
if (res == ERR_INVALID_ARGS) {
return false;
}
for (int i = 0; i < 4 && read < count; i++) {
buffer[read] = num >> (i * 8);
read++;
}
read += res;
}
return true;
}

View file

@ -0,0 +1,21 @@
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#include "bin/crypto.h"
#include "platform/assert.h"
#include "platform/globals.h"
#include "vm/unit_test.h"
namespace dart {
namespace bin {
TEST_CASE(GetRandomBytes) {
const intptr_t kNumRandomBytes = 127;
uint8_t buf[kNumRandomBytes];
const bool res = Crypto::GetRandomBytes(kNumRandomBytes, buf);
EXPECT(res);
}
} // namespace bin
} // namespace dart

View file

@ -1,3 +1,4 @@
GetRandomBytes
CircularLinkedList
Read
FileLength
@ -511,6 +512,8 @@ IsolateReload_PendingConstructorCall_ConcreteToAbstract
IsolateReload_PendingStaticCall_DefinedToNSM
IsolateReload_PendingStaticCall_NSMToDefined
IsolateReload_PendingSuperCall
IsolateReload_TearOff_Equality
IsolateReload_TearOff_List_Set
IsolateReload_EnumEquality
IsolateReload_EnumIdentical
IsolateReload_EnumReorderIdentical
@ -524,6 +527,18 @@ IsolateReload_EnumValuesToString
IsolateReload_DirectSubclasses_Success
IsolateReload_DirectSubclasses_GhostSubclass
IsolateReload_DirectSubclasses_Failure
IsolateReload_ChangeInstanceFormat0
IsolateReload_ChangeInstanceFormat1
IsolateReload_ChangeInstanceFormat2
IsolateReload_ChangeInstanceFormat3
IsolateReload_ChangeInstanceFormat4
IsolateReload_ChangeInstanceFormat5
IsolateReload_ChangeInstanceFormat6
IsolateReload_ChangeInstanceFormat7
IsolateReload_NoLibsModified
IsolateReload_MainLibModified
IsolateReload_ImportedLibModified
IsolateReload_PrefixImportedLibModified
IsolateCurrent
IsolateSpawn
StackLimitInterrupts

View file

@ -28,7 +28,7 @@ bool Platform::Initialize() {
int Platform::NumberOfProcessors() {
return mxr_get_nprocs();
return mxr_get_nprocs_conf();
}

View file

@ -21,8 +21,12 @@
// command line argument which is the path to a file containing a list of tests
// to run, one per line.
// TODO(zra): Make this a command line argument
const char* kRunVmTestsPath = "/boot/bin/dart_vm_tests";
// The simulator only has 512MB;
const intptr_t kOldGenHeapSizeMB = 256;
// Tests that are invalid, wedge, or cause panics.
const char* kSkip[] = {
// These expect a file to exist that we aren't putting in the image.
@ -63,6 +67,8 @@ const char* kSkip[] = {
// No realpath.
"Dart2JSCompilerStats",
"Dart2JSCompileAll",
// Uses too much memory.
"PrintJSON",
};
// Expected to fail/crash.
@ -103,11 +109,11 @@ const char* kBugs[] = {
"TimelinePauses_BeginEnd",
// Needs NativeSymbolResolver
"Service_PersistentHandles",
// Need to investigate:
// Crashes in realloc:
"FindCodeObject",
"ThreadIterator_AddFindRemove",
"PrintJSON",
"SourceReport_Coverage_AllFunctions_ForceCompile",
// pthread TLS destructors are not run.
"ThreadIterator_AddFindRemove",
};
@ -139,10 +145,16 @@ static bool isBug(const char* test) {
static int run_test(const char* test_name) {
const intptr_t kArgc = 2;
const char* argv[3];
const intptr_t kArgc = 3;
const char* argv[kArgc];
char old_gen_arg[64];
snprintf(old_gen_arg, sizeof(old_gen_arg), "--old_gen_heap_size=%ld",
kOldGenHeapSizeMB);
argv[0] = kRunVmTestsPath;
argv[1] = test_name;
argv[1] = old_gen_arg;
argv[2] = test_name;
mx_handle_t p = launchpad_launch(argv[0], kArgc, argv);
if (p < 0) {

View file

@ -57,6 +57,7 @@ void TextBuffer::AddRaw(const uint8_t* buffer,
buf_[msg_len_] = '\0';
}
intptr_t TextBuffer::Printf(const char* format, ...) {
va_list args;
va_start(args, format);
@ -79,6 +80,7 @@ intptr_t TextBuffer::Printf(const char* format, ...) {
return len;
}
// Write a UTF-32 code unit so it can be read by a JSON parser in a string
// literal. Use official encoding from JSON specification. http://json.org/
void TextBuffer::EscapeAndAddCodeUnit(uint32_t codeunit) {
@ -119,6 +121,7 @@ void TextBuffer::EscapeAndAddCodeUnit(uint32_t codeunit) {
}
}
// Write an incomplete UTF-16 code unit so it can be read by a JSON parser in a
// string literal.
void TextBuffer::EscapeAndAddUTF16CodeUnit(uint16_t codeunit) {