Пример #1
0
END_TEST

START_TEST(test_trace_read_transfers)
{
  int status = trace_open("test/4_2_10.trace");
  ck_assert_msg(status != -1, "trace_open should not return -1 if the file does exists");
  Command cmd;

  int transfers = 0;

  cmd_t c;
  int i, f, t, a;
  while (trace_read_cmd(&cmd) != 0) {
    cmd_unpack(&cmd, &c, &i, &f, &t, &a);
    switch (c) {
    case TRANSFER:
      transfers++;
      break;
    }
  }

  ck_assert_msg(transfers == 4, "there should be 4 transfer message, received %d", transfers);

  trace_close();
}
Пример #2
0
END_TEST

START_TEST(test_trace_read_balances)
{
  int status = trace_open("test/4_2_10.trace");
  ck_assert_msg(status != -1, "trace_open should not return -1 if the file does exists");
  Command cmd;

  int balances  = 0;

  cmd_t c;
  int i, f, t, a;
  while (trace_read_cmd(&cmd) != 0) {
    cmd_unpack(&cmd, &c, &i, &f, &t, &a);
    switch (c) {
    case BALANCE:
      balances++;
      break;
    }
  }

  ck_assert_msg(balances == 3, "there should be 3 balance messages, received %d", balances);

  trace_close();
}
Пример #3
0
END_TEST

START_TEST(test_trace_read_deposits)
{
  int status = trace_open("test/4_2_10.trace");
  ck_assert_msg(status != -1, "trace_open should not return -1 if the file does exists");
  Command cmd;

  int deposits  = 0;

  cmd_t c;
  int i, f, t, a;
  while (trace_read_cmd(&cmd) != 0) {
    cmd_unpack(&cmd, &c, &i, &f, &t, &a);
    switch (c) {
    case DEPOSIT:
      deposits++;
      break;
    }
  }

  ck_assert_msg(deposits == 2, "there should be 2 deposit messages, received %d", deposits);

  trace_close();
}
Пример #4
0
END_TEST

START_TEST(test_trace_read_valid_commands)
{
  int status = trace_open("test/4_2_10.trace");
  ck_assert_msg(status != -1, "trace_open should not return -1 if the file does exists");
  Command cmd;

  cmd_t c;
  int i, f, t, a;
  while (trace_read_cmd(&cmd) != 0) {
    cmd_unpack(&cmd, &c, &i, &f, &t, &a);
    switch (c) {
    case CONNECT:
    case EXIT:
    case DEPOSIT:
    case WITHDRAW:
    case TRANSFER:
    case BALANCE:
      break;
    default:
      ck_abort_msg("expected valid command, received %d", c);
    }
  }

  trace_close();
}
Пример #5
0
END_TEST

START_TEST(test_trace_read_single_cmd)
{
  int status = trace_open("test/4_2_10.trace");
  ck_assert_msg(status != -1, "trace_open should not return -1 if the file does exists");
  Command cmd;
  trace_read_cmd(&cmd);
  cmd_t c;
  int i, f, t, a;
  cmd_unpack(&cmd, &c, &i, &f, &t, &a);
  ck_assert_msg(c == CONNECT, "first command should be CONNECT, received %d", c);
}
Пример #6
0
int atm_run(char *trace, int bank_out_fd, int atm_in_fd, int atm_id) {
  int status = trace_open(trace);
  if (status == -1) {
    error_msg(ERR_BAD_TRACE_FILE, "could not open trace file");
    return ERR_BAD_TRACE_FILE;
  }

  byte cmd[MESSAGE_SIZE];
  while (trace_read_cmd(cmd) != 0) {
    status = atm(bank_out_fd, atm_in_fd, atm_id, cmd);

    // We continue if the ATM as unknown. This is ok because the trace
    // file contains commands for all the ATMs.
    if (status == ERR_UNKNOWN_ATM) {
      continue;
    }

    // We display an error message to the ATM user if the account
    // is not valid.
    if (status == ERR_UNKNOWN_ACCOUNT) {
      printf("ATM error: unknown account! ATM Out of service\n");
      continue;
    }

    // We display an error message to the ATM user if the account
    // does not have sufficient funds.
    if (status == ERR_NOFUNDS) {
      printf("not enough funds, retry transaction\n");
      continue;
    }

    // If we receive a status that is not successful we return with
    // the status.
    if (status != SUCCESS) {
      printf("status is %d\n", status);
      return status;
    }
  }

  trace_close();

  return SUCCESS;
}
Пример #7
0
bool retrace_frame(uint64_t* num_cmds)
{
    *num_cmds = 0;

    while (1) {
        char id = trace_read_id();

        switch (id) {
            case TRACE_EOF:
                return false;

            case TRACE_CMD: {
                uint32_t cmd[CMD_MAX_INTS];
                uint32_t length;
                trace_read_cmd(cmd, &length);

                rdp_cmd(cmd, length);
                (*num_cmds)++;

                if (CMD_ID(cmd) == CMD_ID_SYNC_FULL) {
                    return true;
                }

                break;
            }

            case TRACE_RDRAM:
                trace_read_rdram();
                break;

            case TRACE_VI:
                trace_read_vi(plugin_get_vi_registers());
                vi_update();
                break;
        }
    }
}
Пример #8
0
int main(int argc, char *argv[]) {
  if (argc != 2) {
    printf("usage: %s trace_file\n", argv[0]);
    exit(1);
  }

  int result = trace_open(argv[1]);
  if (result == -1) {
    printf("%s: could not open %s\n", argv[0], argv[1]);
    exit(1);
  }

  printf("number of ATMs: %d\n", trace_atm_count());
  printf("number of accounts: %d\n", trace_account_count());

  byte cmd[MESSAGE_SIZE];
  while (trace_read_cmd(cmd) != 0) {
    cmd_dump("TREADER", 0, cmd);
  }

  trace_close();
  
  return 0;
}