示例#1
0
END_TEST

#define test_i(type, var, format)                                         \
  do {                                                                    \
    omlc_set_ ## type(to, var);                                           \
    fail_unless(omlc_get_ ## type(to) == var,                             \
        "Error setting " #type ", expected %" format ", got %" format,    \
        var, omlc_get_ ## type(to));                                      \
    from = to;                                                            \
    fail_unless(omlc_get_ ## type(from) == var,                           \
        "Error copying" #type ", expected %" format ", got %" format,     \
        var, omlc_get_ ## type(to));                                      \
  } while(0)


START_TEST (test_intrinsic)
{
  OmlValueU to, from;
  int32_t i32 = -123234;
  uint32_t u32 = 128937;
  int64_t i64 = -123234892374;
  uint64_t u64 = 128939087987;
  double d = M_PI;

  omlc_zero(to);
  omlc_zero(from);

  test_i(int32, i32, "i");
  test_i(uint32, u32, "u");
  test_i(int64, i64, PRId64);
  test_i(uint64, u64, PRIu64);
  test_i(double, d, "f");
  test_i(bool, 0, "d");
  test_i(bool, 1, "d");
}
示例#2
0
文件: marshal.c 项目: alco90/soml
/** Marshal meta-data for an OML measurement stream's sample
 *
 * An OML measurement stream is written as two bytes; the first one is the
 * counter for the number of elements in the message, and therefore starts at
 * 0, and the second one is the stream's index. This is followed by a
 * marshalled int32 value containing the sequence number, and a double value
 * containing the timestamp.
 *
 * A marshalling message should have been prepared in the MBuffer first with
 * marshal_init(). Actual data can then be marshalled into the message with
 * marshal_values().
 *
 *
 * \param mbuf MBuffer to write marshalled data to
 * \param stream Measurement Stream's index
 * \param seqno message sequence number
 * \param now message time
 * \return 1 if successful, -1 otherwise
 * \see marshal_init, marshal_values, marshal_finalize
 */
int
marshal_measurements(MBuffer* mbuf, int stream, int seqno, double now)
{
  OmlValueU v;
  uint8_t s[2] = { 0, (uint8_t)stream };
  /* Write num-meas (0, for now), and the stream index */
  int result = mbuf_write (mbuf, s, LENGTH (s));

  omlc_zero(v);

  if (result == -1) {
    logerror("Unable to marshal table number and measurement count (mbuf_write())\n");
    mbuf_reset_write (mbuf);
    return -1;
  }

  logdebug("Marshalling sample %d for stream %d\n", seqno, stream);

  omlc_set_int32(v, seqno);
  marshal_value(mbuf, OML_INT32_VALUE, &v);

  omlc_set_double(v, now);
  marshal_value(mbuf, OML_DOUBLE_VALUE, &v);

  return 1;
}
示例#3
0
END_TEST

START_TEST (test_blob)
{
  char *str = "this is a string subtly disguised as a blob";
  OmlValue v, v2;
  OmlValueU vu;
  size_t len = strlen(str);
  void *test = (void*)str;
  size_t bcount;
  size_t alloc_diff;

  oml_value_init(&v);
  oml_value_init(&v2);

  omlc_zero(vu);

  /* Prepare the OmlValueU to be duplicated in the OmlValue */
  omlc_set_blob(vu, test, len);
  bcount = xmembytes();

  oml_value_set(&v, &vu, OML_BLOB_VALUE);
  alloc_diff = xmembytes() - bcount - sizeof(size_t);
  bcount = xmembytes();
  fail_if(alloc_diff < len,
      "OmlValue blob allocated memory not big enough (%d instead of at least %d)",
      alloc_diff, len);

  oml_value_duplicate(&v2, &v);
  fail_if(omlc_get_blob_ptr(*oml_value_get_value(&v2)) == omlc_get_blob_ptr(*oml_value_get_value(&v)),
      "Copied OmlValue blob pointer not allocated properly");
  fail_if(strncmp(omlc_get_blob_ptr(*oml_value_get_value(&v2)), omlc_get_blob_ptr(*oml_value_get_value(&v)), len),
      "Copied OmlValue blob mismatch");
  fail_unless(omlc_get_blob_length(*oml_value_get_value(&v2)) == omlc_get_blob_length(*oml_value_get_value(&v)),
      "Copied OmlValue blob length not set properly (%d instead of %d)",
      omlc_get_blob_length(*oml_value_get_value(&v2)), omlc_get_blob_length(*oml_value_get_value(&v2)));
  alloc_diff = xmembytes() - bcount - sizeof(size_t); /* oml_malloc() always allocates at least sizeof(size_t) more for bookkeeping */
  bcount = xmembytes();
  fail_if(alloc_diff < len,
      "Copied OmlValue blob allocated memory not big enough (%d instead of at least %d)",
      alloc_diff, len);
  fail_unless(omlc_get_blob_size(*oml_value_get_value(&v2)) == oml_malloc_usable_size(omlc_get_blob_ptr(*oml_value_get_value(&v2))),
      "Copied OmlValue blob allocated size not set properly (%d instead of %d)",
      omlc_get_blob_size(*oml_value_get_value(&v2)), oml_malloc_usable_size(omlc_get_blob_ptr(*oml_value_get_value(&v2))));

  oml_value_set_type(&v, OML_UINT64_VALUE);
  fail_unless(xmembytes() < bcount,
      "OmlValue blob  was not freed after oml_value_set_type() (%d allocated, which is not less than %d)",
      xmembytes(), bcount);
  bcount = xmembytes();

  oml_value_reset(&v2);
  fail_unless(xmembytes() < bcount,
      "OmlValue blob  was not freed after oml_value_reset() (%d allocated, which is not less than %d)",
      xmembytes(), bcount);
  bcount = xmembytes();

  oml_value_reset(&v);
  omlc_reset_blob(vu);
}
示例#4
0
END_TEST

START_TEST (test_string)
{
  char *test = "test";
  OmlValue v, v2;
  OmlValueU vu;
  size_t bcount = xmembytes();
  size_t alloc_diff;

  oml_value_init(&v);
  oml_value_init(&v2);

  omlc_zero(vu);

  /* Prepare the OmlValueU to be duplicated in the OmlValue */
  omlc_set_const_string(vu, test);

  oml_value_set(&v, &vu, OML_STRING_VALUE);
  alloc_diff = xmembytes() - bcount - sizeof(size_t);
  bcount = xmembytes();
  fail_if(alloc_diff < strlen(test) + 1,
      "OmlValue string allocated memory not big enough (%d instead of at least %d)",
      alloc_diff, strlen(test) + 1);

  oml_value_duplicate(&v2, &v);
  fail_if(omlc_get_string_ptr(*oml_value_get_value(&v2)) == omlc_get_string_ptr(*oml_value_get_value(&v)),
      "Copied OmlValue string pointer not allocated properly");
  fail_if(strcmp(omlc_get_string_ptr(*oml_value_get_value(&v2)), omlc_get_string_ptr(*oml_value_get_value(&v))),
      "Copied OmlValue string mismatch ('%s' instead of '%s')",
      omlc_get_string_ptr(*oml_value_get_value(&v2)), omlc_get_string_ptr(*oml_value_get_value(&v)));
  fail_unless(omlc_get_string_length(*oml_value_get_value(&v2)) == strlen(omlc_get_string_ptr(*oml_value_get_value(&v2))),
      "Copied OmlValue string length not set properly (%d instead of %d)",
      omlc_get_string_length(*oml_value_get_value(&v2)), strlen(omlc_get_string_ptr(*oml_value_get_value(&v2))) + 1);
  alloc_diff = xmembytes() - bcount - sizeof(size_t); /* oml_malloc() always allocates at least sizeof(size_t) more for bookkeeping */
  bcount = xmembytes();
  fail_if(alloc_diff < strlen(omlc_get_string_ptr(*oml_value_get_value(&v))) + 1,
      "Copied OmlValue string allocated memory not big enough (%d instead of at least %d)",
      alloc_diff, strlen(omlc_get_string_ptr(*oml_value_get_value(&v))) + 1);
  fail_unless(omlc_get_string_size(*oml_value_get_value(&v2)) == oml_malloc_usable_size(omlc_get_string_ptr(*oml_value_get_value(&v2))),
      "Copied OmlValue string allocated size not set properly (%d instead of %d)",
      omlc_get_string_size(*oml_value_get_value(&v2)), oml_malloc_usable_size(omlc_get_string_ptr(*oml_value_get_value(&v2))));
  fail_unless(omlc_get_string_is_const(*oml_value_get_value(&v2)) == 0,
      "Copied OmlValue string should not be constant");

  oml_value_set_type(&v, OML_UINT64_VALUE);
  fail_unless(xmembytes() < bcount,
      "OmlValue string  was not freed after oml_value_set_type() (%d allocated, which is not less than %d)",
      xmembytes(), bcount);
  bcount = xmembytes();

  oml_value_reset(&v2);
  fail_unless(xmembytes() < bcount,
      "OmlValue string  was not freed after oml_value_reset() (%d allocated, which is not less than %d)",
      xmembytes(), bcount);
  bcount = xmembytes();

  oml_value_reset(&v);
  omlc_reset_string(vu);
}
示例#5
0
int
main(int argc, const char *argv[])
{
  int c, i, ret;

  /* Reconstruct command line */
  size_t cmdline_len = 0;
  for(i = 0; i < argc; i++) {
    cmdline_len += strlen(argv[i]) + 1;
  }
  char *cmdline = oml_malloc(cmdline_len);
  cmdline[0] = '\0';
  for(i = 0; i < argc; i++) {
    strncat(cmdline, argv[i], cmdline_len);
    cmdline_len -= strlen(argv[i]);
    strncat(cmdline, " ", cmdline_len);
    cmdline_len--;
  }

  /* Initialize OML */
  if((ret = omlc_init("generator", &argc, argv, NULL)) < 0) {
    logerror("Could not initialise OML\n");
    return -1;
  }

  /* Parse command line arguments */
  poptContext optCon = poptGetContext(NULL, argc, argv, options, 0); /* options is defined in generator_popt.h */
  while ((c = poptGetNextOpt(optCon)) > 0) {}

  /* Initialise measurement points and start OML */
  oml_register_mps(); /* Defined in generator_oml.h */
  if(omlc_start()) {
    logerror("Could not start OML\n");
    return -1;
  }

  /* Inject some metadata about this application */
  OmlValueU v;
  omlc_zero(v);
  omlc_set_string(v, PACKAGE_NAME);
  omlc_inject_metadata(NULL, "appname", &v, OML_STRING_VALUE, NULL);

  omlc_set_string(v, PACKAGE_VERSION);
  omlc_inject_metadata(NULL, "version", &v, OML_STRING_VALUE, NULL);

  omlc_set_string(v, cmdline);
  omlc_inject_metadata(NULL, "cmdline", &v, OML_STRING_VALUE, NULL);
  omlc_reset_string(v);
  oml_free(cmdline);

  /* Inject measurements */
  run(g_opts, g_oml_mps_generator); /* Do some work and injections, see above */

  omlc_close();

  return 0;
}
示例#6
0
END_TEST

START_TEST (test_blobU)
{
  OmlValueU v, v2;
  char *str = "this is a string subtly disguised as a blob";
  char *str2 = "this is another string in blob's clothing, except longer";
  void *test = (void*) str;
  void *test2 = (void*) str2;
  size_t len = strlen(str);
  size_t len2 = strlen(str2);
  size_t bcount = xmembytes(), alloc_diff, size;

  omlc_zero(v);
  omlc_zero(v2);

  /* Set blob (copy) */
  omlc_set_blob(v, test, len);
  fail_if(omlc_get_blob_ptr(v) == test,
      "Test blob pointer not allocated properly");
  fail_if(strncmp(test, omlc_get_blob_ptr(v), len),
      "Test blob mismatch");
  fail_unless(omlc_get_blob_length(v) == len,
      "Test blob length not set properly (%d instead of %d)",
      omlc_get_blob_length(v), len);
  alloc_diff = xmembytes() - bcount - sizeof(size_t);
  bcount = xmembytes();
  fail_if(alloc_diff < len,
      "Test blob allocated memory not big enough (%d instead of at least %d)",
      alloc_diff, len);
  fail_unless(omlc_get_blob_size(v) == oml_malloc_usable_size(omlc_get_string_ptr(v)),
      "Test blob allocated size not set properly (%d instead of %d)",
      omlc_get_blob_size(v), oml_malloc_usable_size(omlc_get_string_ptr(v)));

  /* Duplicate blob*/
  omlc_copy_blob(v2, v);
  fail_if(omlc_get_blob_ptr(v2) == omlc_get_blob_ptr(v),
      "Copied blob not allocated properly");
  fail_if(strncmp(omlc_get_blob_ptr(v2), omlc_get_blob_ptr(v), len),
      "Copied allocated blob mismatch");
  fail_unless(omlc_get_blob_length(v2) == omlc_get_blob_length(v),
      "Copied allocated blob length not set properly (%d instead of %d)",
      omlc_get_blob_length(v2), omlc_get_blob_length(v));
  alloc_diff = xmembytes() - bcount - sizeof(size_t);
  bcount = xmembytes();
  fail_if(alloc_diff < len,
      "Copied allocated blob allocated memory not big enough (%d instead of at least %d)",
      alloc_diff, len);
  fail_unless(omlc_get_blob_size(v) == oml_malloc_usable_size(omlc_get_blob_ptr(v2)),
      "Copied allocated blob allocated size not set properly (%d instead of %d)",
      omlc_get_blob_size(v2), oml_malloc_usable_size(omlc_get_blob_ptr(v2)));

  /* Overwrite blob */
  omlc_set_blob(v, test2, len2);
  /* We know omlc_set_blob() already sets properly, we just want to check it does cleanup previously allocated memory */
  fail_if(xmembytes() > bcount + omlc_get_blob_size(v),
      "Overwritten blob did not deallocate memory properly (%d used but expected %d)",
      xmembytes(), bcount + omlc_get_blob_size(v));

  /* Reset blob and clear allocated pointer */
  omlc_reset_blob(v);
  size = omlc_get_blob_size(v);
  omlc_reset_blob(v);
  fail_unless(omlc_get_blob_ptr(v) == NULL,
      "Reset allocated blob pointer not cleared properly");
  fail_unless(omlc_get_blob_length(v) == 0,
      "Reset allocated blob length not cleared properly");
  alloc_diff = bcount - xmembytes() + sizeof(size_t);
  bcount = xmembytes();
  fail_if(alloc_diff <= size,
      "Reset allocated blob didn't free the memory as expected (%d freed instead at least %d)",
      alloc_diff, size);
  fail_unless(omlc_get_blob_size(v) == 0,
      "Reset allocated blob allocated size not cleared properly");

  omlc_reset_blob(v2);
}