File: starttest.c

package info (click to toggle)
nws 2.11-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,700 kB
  • ctags: 2,820
  • sloc: ansic: 28,849; sh: 3,289; java: 1,205; makefile: 697; perl: 12
file content (60 lines) | stat: -rw-r--r-- 1,093 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <sys/time.h>

#include "starttest.h"
#include "diagnostic.h"  /* FAIL() LOG() */

static int sglobalnum = 0;
static double start_time = 0;

double get_timesincestart() {
	double elapsed_time;
	struct timeval tv;
	double now;
  
	/* if we just started, record the time and return 0 */
	gettimeofday(&tv,NULL);
	now = tv.tv_sec + (tv.tv_usec / 1000000.0);
	elapsed_time = 0;

	if(start_time == 0.0) {
		start_time = now;
	} else {
		elapsed_time = now - start_time;
	}

	return (elapsed_time);
}

int 
starttest(float *result) {
	double elapsed_time;

	sglobalnum++;

	elapsed_time = get_timesincestart();
	*result = (float)elapsed_time;
	return (sglobalnum);
}

int
StartAvailable(const char *opts) {
	return 1;
}

void
StartUseSkill(  const char *opts,
		int *length,
		SkillResult **results) {
	float result;
	int rc;

	/* there is no options for startTime, so we don't need to parse
	 * the options */
	rc = starttest(&result);
	if (rc < 0) {
		AppendResult(startTime, "", 0, 0.0, length, results);
	} else {
		AppendResult(startTime, "", 1, (double)result, length, results);
	}
}