Ejemplo n.º 1
0
void check_kver(void)
{
	int v1, v2, v3;

	tst_parse_kver(tst_test->min_kver, &v1, &v2, &v3);

	if (tst_kvercmp(v1, v2, v3) < 0) {
		tst_brk(TCONF, "The test requires kernel %s or newer",
		        tst_test->min_kver);
	}
}
Ejemplo n.º 2
0
void check_kver(void)
{
	int v1, v2, v3;

	if (tst_parse_kver(tst_test->min_kver, &v1, &v2, &v3)) {
		tst_res(TWARN,
		        "Invalid kernel version %s, expected %%d.%%d.%%d",
		        tst_test->min_kver);
	}

	if (tst_kvercmp(v1, v2, v3) < 0) {
		tst_brk(TCONF, "The test requires kernel %s or newer",
		        tst_test->min_kver);
	}
}
Ejemplo n.º 3
0
int main(int argc, char *argv[])
{
	int i = 1;
	int ret = -1;
	int v1, v2, v3;
	enum op prev_op = ERR;

	if (argc <= 1 || !strcmp(argv[1], "-h")) {
		help(argv[0]);
		return 0;
	}

	while (i < argc) {
		const char *strop = argv[i++];
		const char *strkver;
		int res;

		enum op op = strtop(strop);

		switch (op) {
		case EQ:
		case NE:
		case GE:
		case GT:
		case LE:
		case LT:
			if (ret != -1 && prev_op == ERR) {
				fprintf(stderr, "Expected -a or -o\n");
				return 2;
			}

			if (i >= argc) {
				fprintf(stderr,
					"Expected kernel version after '%s'\n",
					strop);
				return 2;
			}

			strkver = argv[i++];

			if (tst_parse_kver(strkver, &v1, &v2, &v3)) {
				fprintf(stderr,
					"Invalid kernel version '%s'\n",
					strkver);
				return 2;
			}
		break;
		case AND:
		case OR:
			if (ret == -1) {
				fprintf(stderr,
					"The %s must follow expression\n",
					strop);
				return 2;
			}
			prev_op = op;
			continue;
		break;
		case ERR:
			fprintf(stderr, "Invalid operation %s\n", argv[i]);
			return 2;
		}

		res = tst_kvercmp(v1, v2, v3);

		switch (op) {
		case EQ:
			res = (res == 0);
		break;
		case NE:
			res = (res != 0);
		break;
		case GE:
			res = (res >= 0);
		break;
		case GT:
			res = (res > 0);
		break;
		case LE:
			res = (res <= 0);
		break;
		case LT:
			res = (res < 0);
		break;
		default:
		break;
		}

		switch (prev_op) {
		case ERR:
			ret = res;
		break;
		case AND:
			ret = ret && res;
			prev_op = ERR;
		break;
		case OR:
			ret = ret || res;
			prev_op = ERR;
		break;
		default:
		break;
		}
	}

	if (prev_op != ERR) {
		fprintf(stderr, "Useless -a or -o at the end\n");
		return 2;
	}

	return !ret;
}