Ejemplo n.º 1
0
void testParse() {
  VM vm;

  {
    EXPECT_INT_EQ(vm.parse("1").asInteger(vm), 1);
    EXPECT_INT_EQ(vm.parse("42").asInteger(vm), 42);
  }

  {
    EXPECT(vm.parse("#t").asBool(vm) == true);
    EXPECT(vm.parse("#f").asBool(vm) == false);
  }

  {
    Value res = vm.parse("a");
    EXPECT(res.isSymbol());
  }

  {
    Value res = vm.parse("\"a\"");
    EXPECT(res == vm.makeString("a"));
  }

  {
    Value res = vm.parse("(a b)");
    Value a = vm.makeSymbol("a");
    Value b = vm.makeSymbol("b");
    EXPECT(res == vm.makeList(a, b));
  }
}
Ejemplo n.º 2
0
void test_modulo(void) {
  EXPECT_INT_EQ(3, az_modulo(10, 7));
  EXPECT_INT_EQ(4, az_modulo(-10, 7));
  EXPECT_INT_EQ(-4, az_modulo(10, -7));
  EXPECT_INT_EQ(-3, az_modulo(-10, -7));

  EXPECT_INT_EQ(0, az_modulo(0, 7));
  EXPECT_INT_EQ(0, az_modulo(0, -7));
  EXPECT_INT_EQ(0, az_modulo(14, 7));
  EXPECT_INT_EQ(0, az_modulo(14, -7));
  EXPECT_INT_EQ(0, az_modulo(-14, 7));
  EXPECT_INT_EQ(0, az_modulo(-14, -7));
}
Ejemplo n.º 3
0
void testSymbols() {
  VM vm;

  Value a = vm.makeSymbol("a");
  Value b = vm.makeSymbol("b");
  Value a2 = vm.makeSymbol("a");

  Value one = vm.makeInteger(1);
  Value two = vm.makeInteger(2);

  EXPECT(a == a2);
  EXPECT(a != b);
  EXPECT(a2 != b);

  Value map = vm.makeList(
    vm.makeCons(a, one),
    vm.makeCons(b, two));

  EXPECT_INT_EQ(map_lookup(vm, map, a).asInteger(vm), 1);
  EXPECT_INT_EQ(map_lookup(vm, map, b).asInteger(vm), 2);
}
Ejemplo n.º 4
0
static int test_span_id_round_trip(const char *str)
{
    struct htrace_span_id id;
    char err[512], str2[HTRACE_SPAN_ID_STRING_LENGTH + 1];
    size_t err_len = sizeof(err);

    err[0] = '\0';
    htrace_span_id_parse(&id, str, err, err_len);
    EXPECT_STR_EQ("", err);
    EXPECT_INT_EQ(1, htrace_span_id_to_str(&id, str2, sizeof(str2)));
    EXPECT_STR_EQ(str, str2);
    return 0;
}
Ejemplo n.º 5
0
void testParseAndEval() {
  VM vm;

  {
    Value plus = vm.syms.add;
    Value add = vm.objs.builtin_add;

    Value pair = vm.makeCons(plus, add);
    Value env = vm.makeCons(pair, vm.nil);

    Value input = vm.parse("(+ 1 2)");
    Value res = eval(vm, input, env);

    EXPECT_INT_EQ(res.asInteger(vm), 3);
  }

  {
    Value scons = vm.syms.Cons;
    Value cons = vm.objs.builtin_cons;

    Value env = vm.makeList(vm.makeCons(scons, cons));

    Value input = vm.parse("((letlambdas ( ((myfunc x y) (cons x y)) ) myfunc) 1 2)");
    Value res = eval(vm, input, env);

    EXPECT(res == vm.makeCons(vm.makeInteger(1), vm.makeInteger(2)));
  }

  {
    Value input = vm.parse("((import core +) 1 2)");
    Value res = eval(vm, input, vm.nil);

    EXPECT_INT_EQ(res.asInteger(vm), 3);
  }

}
Ejemplo n.º 6
0
void testEval() {
  VM vm;

  Value plus = vm.syms.add;
  Value add = vm.objs.builtin_add;
  Value _if = vm.syms.if_;
  Value _true = vm.true_;
  Value _false = vm.false_;
  Value one = vm.makeInteger(1);
  Value two = vm.makeInteger(2);

  {
    EXPECT_INT_EQ(eval(vm, vm.makeInteger(1), vm.nil).asInteger(vm), 1);
    EXPECT_INT_EQ(eval(vm, vm.makeInteger(42), vm.nil).asInteger(vm), 42);
  }

  {
    Value list = vm.makeList(add, one, two);

    EXPECT_INT_EQ(eval(vm, list, vm.nil).asInteger(vm), 3);
  }

  {
    Value a = vm.makeSymbol("a");
    Value pair = vm.makeCons(a, vm.makeInteger(42));
    Value env = vm.makeCons(pair, vm.nil);
    EXPECT_INT_EQ(eval(vm, a, env).asInteger(vm), 42);
  }

  {
    Value list = vm.makeList(plus, one, two);

    Value pair = vm.makeCons(plus, add);
    Value env = vm.makeCons(pair, vm.nil);
    EXPECT_INT_EQ(eval(vm, list, env).asInteger(vm), 3);
  }

  {
    Value list = vm.makeList(_if, _true, one, two);
    EXPECT_INT_EQ(eval(vm, list, vm.nil).asInteger(vm), 1);
  }

  {
    Value list = vm.makeList(_if, _false, one, two);
    EXPECT_INT_EQ(eval(vm, list, vm.nil).asInteger(vm), 2);
  }

}
Ejemplo n.º 7
0
void testInterpret() {
  VM vm;
  
  Value values[] = {
    vm.makeInteger(1),
    vm.makeInteger(2),
    vm.makeInteger(-1),
  };

  const unsigned char instrs[] = {Opcode::Add, 0, 1, 2, Opcode::Call};

  Frame frame;
  frame.ip = instrs;
  frame.values = values;
  frame.size = 3;

  interpret(vm, &frame);

  EXPECT_INT_EQ(values[2].asInteger(vm), 3);
}
Ejemplo n.º 8
0
static int createZeroCopyTestFile(hdfsFS fs, char *testFileName,
                                  size_t testFileNameLen)
{
    int blockIdx, blockLen;
    hdfsFile file;
    uint8_t *data;

    snprintf(testFileName, testFileNameLen, "/zeroCopyTestFile.%d.%d",
             getpid(), rand());
    file = hdfsOpenFile(fs, testFileName, O_WRONLY, 0, 1,
                        TEST_ZEROCOPY_FULL_BLOCK_SIZE);
    EXPECT_NONNULL(file);
    for (blockIdx = 0; blockIdx < TEST_ZEROCOPY_NUM_BLOCKS; blockIdx++) {
        blockLen = getZeroCopyBlockLen(blockIdx);
        data = getZeroCopyBlockData(blockIdx);
        EXPECT_NONNULL(data);
        EXPECT_INT_EQ(blockLen, hdfsWrite(fs, file, data, blockLen));
    }
    EXPECT_ZERO(hdfsCloseFile(fs, file));
    return 0;
}
Ejemplo n.º 9
0
static int doTestZeroCopyReads(hdfsFS fs, const char *fileName)
{
    hdfsFile file = NULL;
    struct hadoopRzOptions *opts = NULL;
    struct hadoopRzBuffer *buffer = NULL;
    uint8_t *block;

    file = hdfsOpenFile(fs, fileName, O_RDONLY, 0, 0, 0);
    EXPECT_NONNULL(file);
    opts = hadoopRzOptionsAlloc();
    EXPECT_NONNULL(opts);
    EXPECT_ZERO(hadoopRzOptionsSetSkipChecksum(opts, 1));
    /* haven't read anything yet */
    EXPECT_ZERO(expectFileStats(file, 0LL, 0LL, 0LL, 0LL));
    block = getZeroCopyBlockData(0);
    EXPECT_NONNULL(block);
    /* first read is half of a block. */
    buffer = hadoopReadZero(file, opts, TEST_ZEROCOPY_FULL_BLOCK_SIZE / 2);
    EXPECT_NONNULL(buffer);
    EXPECT_INT_EQ(TEST_ZEROCOPY_FULL_BLOCK_SIZE / 2,
          hadoopRzBufferLength(buffer));
    EXPECT_ZERO(memcmp(hadoopRzBufferGet(buffer), block,
          TEST_ZEROCOPY_FULL_BLOCK_SIZE / 2));
    hadoopRzBufferFree(file, buffer);
    /* read the next half of the block */
    buffer = hadoopReadZero(file, opts, TEST_ZEROCOPY_FULL_BLOCK_SIZE / 2);
    EXPECT_NONNULL(buffer);
    EXPECT_INT_EQ(TEST_ZEROCOPY_FULL_BLOCK_SIZE / 2,
          hadoopRzBufferLength(buffer));
    EXPECT_ZERO(memcmp(hadoopRzBufferGet(buffer),
          block + (TEST_ZEROCOPY_FULL_BLOCK_SIZE / 2),
          TEST_ZEROCOPY_FULL_BLOCK_SIZE / 2));
    hadoopRzBufferFree(file, buffer);
    free(block);
    EXPECT_ZERO(expectFileStats(file, TEST_ZEROCOPY_FULL_BLOCK_SIZE, 
              TEST_ZEROCOPY_FULL_BLOCK_SIZE,
              TEST_ZEROCOPY_FULL_BLOCK_SIZE,
              TEST_ZEROCOPY_FULL_BLOCK_SIZE));
    /* Now let's read just a few bytes. */
    buffer = hadoopReadZero(file, opts, SMALL_READ_LEN);
    EXPECT_NONNULL(buffer);
    EXPECT_INT_EQ(SMALL_READ_LEN, hadoopRzBufferLength(buffer));
    block = getZeroCopyBlockData(1);
    EXPECT_NONNULL(block);
    EXPECT_ZERO(memcmp(block, hadoopRzBufferGet(buffer), SMALL_READ_LEN));
    hadoopRzBufferFree(file, buffer);
    EXPECT_INT64_EQ(
          (int64_t)TEST_ZEROCOPY_FULL_BLOCK_SIZE + (int64_t)SMALL_READ_LEN,
          hdfsTell(fs, file));
    EXPECT_ZERO(expectFileStats(file,
          TEST_ZEROCOPY_FULL_BLOCK_SIZE + SMALL_READ_LEN,
          TEST_ZEROCOPY_FULL_BLOCK_SIZE + SMALL_READ_LEN,
          TEST_ZEROCOPY_FULL_BLOCK_SIZE + SMALL_READ_LEN,
          TEST_ZEROCOPY_FULL_BLOCK_SIZE + SMALL_READ_LEN));

    /* Clear 'skip checksums' and test that we can't do zero-copy reads any
     * more.  Since there is no ByteBufferPool set, we should fail with
     * EPROTONOSUPPORT.
     */
    EXPECT_ZERO(hadoopRzOptionsSetSkipChecksum(opts, 0));
    EXPECT_NULL(hadoopReadZero(file, opts, TEST_ZEROCOPY_FULL_BLOCK_SIZE));
    EXPECT_INT_EQ(EPROTONOSUPPORT, errno);

    /* Verify that setting a NULL ByteBufferPool class works. */
    EXPECT_ZERO(hadoopRzOptionsSetByteBufferPool(opts, NULL));
    EXPECT_ZERO(hadoopRzOptionsSetSkipChecksum(opts, 0));
    EXPECT_NULL(hadoopReadZero(file, opts, TEST_ZEROCOPY_FULL_BLOCK_SIZE));
    EXPECT_INT_EQ(EPROTONOSUPPORT, errno);

    /* Now set a ByteBufferPool and try again.  It should succeed this time. */
    EXPECT_ZERO(hadoopRzOptionsSetByteBufferPool(opts,
          ELASTIC_BYTE_BUFFER_POOL_CLASS));
    buffer = hadoopReadZero(file, opts, TEST_ZEROCOPY_FULL_BLOCK_SIZE);
    EXPECT_NONNULL(buffer);
    EXPECT_INT_EQ(TEST_ZEROCOPY_FULL_BLOCK_SIZE, hadoopRzBufferLength(buffer));
    EXPECT_ZERO(expectFileStats(file,
          (2 * TEST_ZEROCOPY_FULL_BLOCK_SIZE) + SMALL_READ_LEN,
          (2 * TEST_ZEROCOPY_FULL_BLOCK_SIZE) + SMALL_READ_LEN,
          (2 * TEST_ZEROCOPY_FULL_BLOCK_SIZE) + SMALL_READ_LEN,
          TEST_ZEROCOPY_FULL_BLOCK_SIZE + SMALL_READ_LEN));
    EXPECT_ZERO(memcmp(block + SMALL_READ_LEN, hadoopRzBufferGet(buffer),
        TEST_ZEROCOPY_FULL_BLOCK_SIZE - SMALL_READ_LEN));
    free(block);
    block = getZeroCopyBlockData(2);
    EXPECT_NONNULL(block);
    EXPECT_ZERO(memcmp(block, (uint8_t*)hadoopRzBufferGet(buffer) +
        (TEST_ZEROCOPY_FULL_BLOCK_SIZE - SMALL_READ_LEN), SMALL_READ_LEN));
    hadoopRzBufferFree(file, buffer);

    /* Check the result of a zero-length read. */
    buffer = hadoopReadZero(file, opts, 0);
    EXPECT_NONNULL(buffer);
    EXPECT_NONNULL(hadoopRzBufferGet(buffer));
    EXPECT_INT_EQ(0, hadoopRzBufferLength(buffer));
    hadoopRzBufferFree(file, buffer);

    /* Check the result of reading past EOF */
    EXPECT_INT_EQ(0, hdfsSeek(fs, file, TEST_ZEROCOPY_FILE_LEN));
    buffer = hadoopReadZero(file, opts, 1);
    EXPECT_NONNULL(buffer);
    EXPECT_NULL(hadoopRzBufferGet(buffer));
    hadoopRzBufferFree(file, buffer);

    /* Cleanup */
    free(block);
    hadoopRzOptionsFree(opts);
    EXPECT_ZERO(hdfsCloseFile(fs, file));
    return 0;
}