Beispiel #1
0
CJsonNode g_LegacyStatToJson(CNetServer server, bool verbose)
{
    const string stat_cmd(verbose ? "STAT ALL" : "STAT");

    CNetServerMultilineCmdOutput output(server.ExecWithRetry(stat_cmd, true));

    CJsonNode stat_info(CJsonNode::NewObjectNode());
    CJsonNode jobs_by_status(CJsonNode::NewObjectNode());;
    stat_info.SetByKey("JobsByStatus", jobs_by_status);
    CJsonNode section_entries;

    string line;
    CTempString key, value;

    while (output.ReadLine(line)) {
        if (line.empty() || isspace(line[0]))
            continue;

        if (line[0] == '[') {
            size_t section_name_len = line.length();
            while (--section_name_len > 0 &&
                    (line[section_name_len] == ':' ||
                    line[section_name_len] == ']' ||
                    isspace(line[section_name_len])))
                ;
            line.erase(0, 1);
            line.resize(section_name_len);
            stat_info.SetByKey(line,
                    section_entries = CJsonNode::NewArrayNode());
        }
        else if (section_entries) {
            section_entries.AppendString(line);
        }
        else if (NStr::SplitInTwo(line, ":", key, value)) {
            value = NStr::TruncateSpaces_Unsafe(value, NStr::eTrunc_Begin);
            if (CNetScheduleAPI::StringToStatus(key) !=
                    CNetScheduleAPI::eJobNotFound)
                jobs_by_status.SetInteger(key, NStr::StringToInt8(value));
            else {
                if (key == "Executable path" &&
                        g_FixMisplacedPID(stat_info, value, "PID")) {
                    if (!stat_info.HasKey("Version"))
                        stat_info.SetString("Version", "Unknown");

                    if (!stat_info.HasKey("Build date"))
                        stat_info.SetString("Build date", "Unknown");
                }
                stat_info.SetByKey(key, CJsonNode::GuessType(value));
            }
        }
    }

    return stat_info;
}
Beispiel #2
0
int main(int argc, char **argv) {
    bool          succeed  = false;
    char         *redirout = (char*)stdout;
    char         *redirerr = (char*)stderr;
    char         *defs     = NULL;

    con_init();
    OPTS_OPTION_U16(OPTION_MEMDUMPCOLS) = 16;

    /*
     * Command line option parsing commences now We only need to support
     * a few things in the test suite.
     */
    while (argc > 1) {
        ++argv;
        --argc;

        if (argv[0][0] == '-') {
            if (parsecmd("redirout", &argc, &argv, &redirout, 1, false))
                continue;
            if (parsecmd("redirerr", &argc, &argv, &redirerr, 1, false))
                continue;
            if (parsecmd("defs",     &argc, &argv, &defs,     1, false))
                continue;

            con_change(redirout, redirerr);

            if (!strcmp(argv[0]+1, "debug")) {
                OPTS_OPTION_BOOL(OPTION_DEBUG) = true;
                continue;
            }
            if (!strcmp(argv[0]+1, "memchk")) {
                OPTS_OPTION_BOOL(OPTION_MEMCHK) = true;
                continue;
            }
            if (!strcmp(argv[0]+1, "nocolor")) {
                con_color(0);
                continue;
            }

            con_err("invalid argument %s\n", argv[0]+1);
            return -1;
        }
    }
    con_change(redirout, redirerr);
    succeed = test_perform("tests", defs);
    stat_info();

    return (succeed) ? EXIT_SUCCESS : EXIT_FAILURE;
}
Beispiel #3
0
CJsonNode g_LegacyStatToJson(CNetServer server, bool verbose)
{
    const string stat_cmd(verbose ? "STAT ALL" : "STAT");

    CNetServerMultilineCmdOutput output(server.ExecWithRetry(stat_cmd));

    CJsonNode stat_info(CJsonNode::NewObjectNode());
    CJsonNode jobs_by_status(CJsonNode::NewObjectNode());;
    stat_info.SetNode("JobsByStatus", jobs_by_status);
    CJsonNode section_entries;

    string line;
    CTempString key, value;

    while (output.ReadLine(line)) {
        if (line.empty() || isspace(line[0]))
            continue;

        if (line[0] == '[') {
            size_t section_name_len = line.length();
            while (--section_name_len > 0 &&
                    (line[section_name_len] == ':' ||
                    line[section_name_len] == ']' ||
                    isspace(line[section_name_len])))
                ;
            line.erase(0, 1);
            line.resize(section_name_len);
            stat_info.SetNode(line,
                    section_entries = CJsonNode::NewArrayNode());
        } else if (section_entries)
            section_entries.PushString(line);
        else if (NStr::SplitInTwo(line, ":", key, value)) {
            value = NStr::TruncateSpaces(value, NStr::eTrunc_Begin);
            if (CNetScheduleAPI::StringToStatus(key) ==
                    CNetScheduleAPI::eJobNotFound)
                stat_info.SetString(key, value);
            else
                jobs_by_status.SetNumber(key, NStr::StringToInt8(value));
        }
    }

    return stat_info;
}
Beispiel #4
0
int main (int argc, char *argv[])
{
  char file1[1024];
  char file2[1024];
  FILE *f1, *f2;
  long sz1, sz2, i;
  real *buf1, *buf2, b1, b2;
  char *c1, *c2;
  int differ=0;
  size_t foo;
  Quadruplet res;
  int identical=0, flatratio=0, zerorequired=0;
  if (argc != 4) {
    fprintf (stderr, "%s admits exactly two arguments: -flag (z or f) file1 and file2\n", argv[0]);
    exit (1);
  }
  if (*(argv[1]+1) == 'z') zerorequired=1;
  snprintf (file1, 1020, "%s", argv[2]);
  snprintf (file2, 1020, "%s", argv[3]);

  f1 = fopen (file1, "r");
  if (f1 == NULL) {
    fprintf (stderr, "I cannot open %s.\n", file1);
    exit (1);
  }
  fseek (f1, 0, SEEK_END);
  sz1 = ftell(f1);
  fseek (f1, 0, SEEK_SET);

  f2 = fopen (file2, "r");
  if (f2 == NULL) {
    fprintf (stderr, "I cannot open %s.\n", file2);
    exit (1);
  }
  fseek (f2, 0, SEEK_END);
  sz2 = ftell(f2);
  fseek (f2, 0, SEEK_SET);
  if (sz1 != sz2) {
    fprintf (stderr, "Error : %s and %s have different sizes.\n", file1, file2);
    exit (1);
  }
  buf1 = (real *)malloc (sz1);
  buf2 = (real *)malloc (sz2);
  if ((buf1 == NULL) || (buf2 == NULL)) {
    fprintf (stderr, "Error : cannot allocate memory.\n");
    exit (1);
  }
  foo = fread (buf1, sz1, 1, f1);
  foo = fread (buf2, sz2, 1, f2);
  fclose (f1);
  fclose (f2);
  c1 = (char *)buf1;
  c2 = (char *)buf2;
  for (i = 0; i < sz1; i++) {
    if (c1[i] != c2[i])
      differ = 1;
  }
  if (differ) 
    printf ("%s and %s differ.\n", file1, file2);
  else {
    printf ("%s and %s are identical.\n", file1, file2);
    identical = 1;
  }
  sz1 /= sizeof(real);
  sz2 /= sizeof(real);
  res = stat_info (buf1, sz1);
  printf ("Size of file : %ld bytes, ie %ld ", sz1*sizeof(real), sz1);
  if (sizeof(real) == 4)
    printf ("single precision floating point values\n");
  else
    printf ("double precision floating point values\n");
  printf ("File1: min = %g\tmax = %g\tavg = %g\trms = %g\n", res.min, res.max, res.avg, res.rms);
  res = stat_info (buf2, sz1);
  printf ("File2: min = %g\tmax = %g\tavg = %g\trms = %g\n", res.min, res.max, res.avg, res.rms);
  for (i = 0; i < sz1; i++) {
    b1 = buf1[i];
    b2 = buf2[i];
    buf1[i] = b1-b2;
    buf2[i] = b2/b1;
  }
  res = stat_info (buf1, sz1);
  printf ("(1)-(2): min = %g\tmax = %g\tavg = %g\trms = %g\n", res.min, res.max, res.avg, res.rms);
  res = stat_info (buf2, sz1);
  printf ("Ratio 2/1: min = %g\tmax = %g\tavg = %g\trms = %g\n", res.min, res.max, res.avg, res.rms);
  if (fabs(res.rms/res.avg) < 1e-12) {
    printf ("flat ratio\n");
    flatratio = 1;
  }
  else
    printf ("variable ratio\n");
  for (i = 0; i < sz1; i++)
    buf2[i] = 1.0-buf2[i];
  res = stat_info (buf2, sz1);
  printf ("(1-2)/(1): min = %g\tmax = %g\tavg = %g\trms = %g\n", res.min, res.max, res.avg, res.rms);
  if ((flatratio && !zerorequired) || identical) {
    printf ("%sTEST PASSED (SUCCESS) : files ",BOLDGREEN);
    if (identical)
      printf ("are identical%s\n",RESET);
    else
      printf ("have a flat ratio%s\n",RESET);
  } else
    printf ("%sTEST FAILED : files differ%s\n",BOLDRED,RESET);
  free (buf1);
  free (buf2);
}
Beispiel #5
0
int main(int argc, char **argv) {
    bool          extract   = true;
    char         *redirout  = (char*)stdout;
    char         *redirerr  = (char*)stderr;
    char         *file      = NULL;
    char        **files     = NULL;
    pak_file_t   *pak       = NULL;
    size_t        iter      = 0;

    con_init();

    /*
     * Command line option parsing commences now We only need to support
     * a few things in the test suite.
     */
    while (argc > 1) {
        ++argv;
        --argc;

        if (argv[0][0] == '-') {
            if (parsecmd("redirout",  &argc, &argv, &redirout,  1, false))
                continue;
            if (parsecmd("redirerr",  &argc, &argv, &redirerr,  1, false))
                continue;
            if (parsecmd("file",      &argc, &argv, &file,      1, false))
                continue;

            con_change(redirout, redirerr);

            switch (argv[0][1]) {
                case 'e': extract = true;  continue;
                case 'c': extract = false; continue;
            }

            if (!strcmp(argv[0]+1, "debug")) {
                OPTS_OPTION_BOOL(OPTION_DEBUG) = true;
                continue;
            }
            if (!strcmp(argv[0]+1, "memchk")) {
                OPTS_OPTION_BOOL(OPTION_MEMCHK) = true;
                continue;
            }
            if (!strcmp(argv[0]+1, "nocolor")) {
                con_color(0);
                continue;
            }
        }

        vec_push(files, argv[0]);
    }
    con_change(redirout, redirerr);


    if (!file) {
        con_err("-file must be specified for output/input PAK file\n");
        vec_free(files);
        return EXIT_FAILURE;
    }

    if (extract) {
        if (!(pak = pak_open(file, "r"))) {
            con_err("failed to open PAK file %s\n", file);
            vec_free(files);
            return EXIT_FAILURE;
        }

        if (!pak_extract_all(pak, "./")) {
            con_err("failed to extract PAK %s (files may be missing)\n", file);
            pak_close(pak);
            vec_free(files);
            return EXIT_FAILURE;
        }

        /* not possible */
        pak_close(pak);
        vec_free(files);
        stat_info();

        return EXIT_SUCCESS;
    }

    if (!(pak = pak_open(file, "w"))) {
        con_err("failed to open PAK %s for writing\n", file);
        vec_free(files);
        return EXIT_FAILURE;
    }

    for (iter = 0; iter < vec_size(files); iter++) {
        if (!(pak_insert_one(pak, files[iter]))) {
            con_err("failed inserting %s for PAK %s\n", files[iter], file);
            pak_close(pak);
            vec_free(files);
            return EXIT_FAILURE;
        }
    }

    /* not possible */
    pak_close(pak);
    vec_free(files);

    stat_info();
    return EXIT_SUCCESS;
}