Revision 66516e5e

View differences:

src/Tests/topology_test.c
31 31
static int port = 6666;
32 32
static int srv_port;
33 33
static const char *srv_ip;
34
static char *fprefix;
34 35

  
35 36
static void cmdline_parse(int argc, char *argv[])
36 37
{
37 38
  int o;
38 39

  
39
  while ((o = getopt(argc, argv, "p:i:P:I:")) != -1) {
40
  while ((o = getopt(argc, argv, "s:p:i:P:I:")) != -1) {
40 41
    switch(o) {
41 42
      case 'p':
42 43
        srv_port = atoi(optarg);
......
50 51
      case 'I':
51 52
        my_addr = iface_addr(optarg);
52 53
        break;
54
      case 's':
55
        fprefix = strdup(optarg);
56
        break;
53 57
      default:
54 58
        fprintf(stderr, "Error: unknown option %c\n", o);
55 59

  
......
97 101
      nodeid_free(remote);
98 102
    } else {
99 103
      topParseData(NULL, 0);
100
      if (cnt++ % 10 == 0) {
104
      if (cnt % 10 == 0) {
101 105
        const struct nodeID **neighbourhoods;
102 106
        int n, i;
103 107

  
104 108
        neighbourhoods = topGetNeighbourhood(&n);
105
        printf("I have %d neighbourhoods:\n", n);
109
        printf("I have %d neighbours:\n", n);
106 110
        for (i = 0; i < n; i++) {
107 111
          printf("\t%d: %s\n", i, node_addr(neighbourhoods[i]));
108 112
        }
113
        fflush(stdout);
114
        if (fprefix) {
115
          FILE *f;
116
          char fname[64];
117

  
118
          sprintf(fname, "%s-%d.txt", fprefix, port);
119
          f = fopen(fname, "w");
120
          if (f) fprintf(f, "#Cache size: %d\n", n);
121
          for (i = 0; i < n; i++) {
122
            if (f) fprintf(f, "%d\t\t%d\t%s\n", port, i, node_addr(neighbourhoods[i]));
123
          }
124
          fclose(f);
125
        }
109 126
      }
127
      cnt++;
110 128
    }
111 129
  }
112 130
}

Also available in: Unified diff