1f08c3bdfSopenharmony_ci/******************************************************************************/
2f08c3bdfSopenharmony_ci/*                                                                            */
3f08c3bdfSopenharmony_ci/* Copyright (c) International Business Machines  Corp., 2008                 */
4f08c3bdfSopenharmony_ci/*                                                                            */
5f08c3bdfSopenharmony_ci/* This program is free software;  you can redistribute it and/or modify      */
6f08c3bdfSopenharmony_ci/* it under the terms of the GNU General Public License as published by       */
7f08c3bdfSopenharmony_ci/* the Free Software Foundation; either version 2 of the License, or          */
8f08c3bdfSopenharmony_ci/* (at your option) any later version.                                        */
9f08c3bdfSopenharmony_ci/*                                                                            */
10f08c3bdfSopenharmony_ci/* This program is distributed in the hope that it will be useful,            */
11f08c3bdfSopenharmony_ci/* but WITHOUT ANY WARRANTY;  without even the implied warranty of            */
12f08c3bdfSopenharmony_ci/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See                  */
13f08c3bdfSopenharmony_ci/* the GNU General Public License for more details.                           */
14f08c3bdfSopenharmony_ci/*                                                                            */
15f08c3bdfSopenharmony_ci/* You should have received a copy of the GNU General Public License          */
16f08c3bdfSopenharmony_ci/* along with this program;  if not, write to the Free Software               */
17f08c3bdfSopenharmony_ci/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    */
18f08c3bdfSopenharmony_ci/*                                                                            */
19f08c3bdfSopenharmony_ci/******************************************************************************/
20f08c3bdfSopenharmony_ci
21f08c3bdfSopenharmony_ci/******************************************************************************/
22f08c3bdfSopenharmony_ci/*                                                                            */
23f08c3bdfSopenharmony_ci/* File:        cpuctl_latency_test.c                                         */
24f08c3bdfSopenharmony_ci/*                                                                            */
25f08c3bdfSopenharmony_ci/* Description: This is a c program that runs a task which tries to keep cpu  */
26f08c3bdfSopenharmony_ci/*              busy in doing some calculations. The task will be used to     */
27f08c3bdfSopenharmony_ci/*              check the latency under group scheduling.                     */
28f08c3bdfSopenharmony_ci/*              The file is to be used by script                              */
29f08c3bdfSopenharmony_ci/*                                                                            */
30f08c3bdfSopenharmony_ci/* Total Tests: 2                                                             */
31f08c3bdfSopenharmony_ci/*                                                                            */
32f08c3bdfSopenharmony_ci/* Test Name:   cpu_controller_latency_tests                                  */
33f08c3bdfSopenharmony_ci/*                                                                            */
34f08c3bdfSopenharmony_ci/* Test Assertion                                                             */
35f08c3bdfSopenharmony_ci/*              Please refer to the file cpuctl_testplan.txt                  */
36f08c3bdfSopenharmony_ci/*                                                                            */
37f08c3bdfSopenharmony_ci/* Author:      Sudhir Kumar skumar@linux.vnet.ibm.com                        */
38f08c3bdfSopenharmony_ci/*                                                                            */
39f08c3bdfSopenharmony_ci/* History:                                                                   */
40f08c3bdfSopenharmony_ci/* Created-     26/11/2008 -Sudhir Kumar <skumar@linux.vnet.ibm.com>          */
41f08c3bdfSopenharmony_ci/*                                                                            */
42f08c3bdfSopenharmony_ci/******************************************************************************/
43f08c3bdfSopenharmony_ci
44f08c3bdfSopenharmony_ci#include <errno.h>
45f08c3bdfSopenharmony_ci#include <err.h>
46f08c3bdfSopenharmony_ci#include <signal.h>
47f08c3bdfSopenharmony_ci#include <stdio.h>
48f08c3bdfSopenharmony_ci#include <stdlib.h>
49f08c3bdfSopenharmony_ci#include <string.h>
50f08c3bdfSopenharmony_ci#include <unistd.h>
51f08c3bdfSopenharmony_ci
52f08c3bdfSopenharmony_ci#include "../libcontrollers/libcontrollers.h"
53f08c3bdfSopenharmony_ci
54f08c3bdfSopenharmony_cichar *TCID = "cpu_controller_latency_tests";
55f08c3bdfSopenharmony_ciint TST_TOTAL = 2;
56f08c3bdfSopenharmony_ci
57f08c3bdfSopenharmony_civoid sighandler(int i)
58f08c3bdfSopenharmony_ci{
59f08c3bdfSopenharmony_ci	exit(0);
60f08c3bdfSopenharmony_ci}
61f08c3bdfSopenharmony_ci
62f08c3bdfSopenharmony_ciint main(int argc, char *argv[])
63f08c3bdfSopenharmony_ci{
64f08c3bdfSopenharmony_ci	char mytaskfile[FILENAME_MAX];
65f08c3bdfSopenharmony_ci	int test_num;
66f08c3bdfSopenharmony_ci
67f08c3bdfSopenharmony_ci	struct sigaction newaction, oldaction;
68f08c3bdfSopenharmony_ci
69f08c3bdfSopenharmony_ci	/* TODO (garrcoop): add error handling. */
70f08c3bdfSopenharmony_ci	sigemptyset(&newaction.sa_mask);
71f08c3bdfSopenharmony_ci	sigaddset(&newaction.sa_mask, SIGUSR1);
72f08c3bdfSopenharmony_ci	newaction.sa_handler = &sighandler;
73f08c3bdfSopenharmony_ci	sigaction(SIGUSR1, &newaction, &oldaction);
74f08c3bdfSopenharmony_ci
75f08c3bdfSopenharmony_ci	if (argc < 2 || argc > 3) {
76f08c3bdfSopenharmony_ci		errx(EINVAL, "TBROK\t Invalid #args received from script"
77f08c3bdfSopenharmony_ci		     " The test will run without any cpu load");
78f08c3bdfSopenharmony_ci	}
79f08c3bdfSopenharmony_ci
80f08c3bdfSopenharmony_ci	/* Migrate the task to its group if applicable */
81f08c3bdfSopenharmony_ci	test_num = atoi(argv[1]);
82f08c3bdfSopenharmony_ci	if (test_num < 0) {
83f08c3bdfSopenharmony_ci		errx(EINVAL,
84f08c3bdfSopenharmony_ci		     "Invalid test number received from script. "
85f08c3bdfSopenharmony_ci		     "Skipping load creation");
86f08c3bdfSopenharmony_ci	}
87f08c3bdfSopenharmony_ci
88f08c3bdfSopenharmony_ci	if (test_num == 2) {
89f08c3bdfSopenharmony_ci		strncpy(mytaskfile, argv[2], FILENAME_MAX);
90f08c3bdfSopenharmony_ci		strncat(mytaskfile, "/tasks",
91f08c3bdfSopenharmony_ci			FILENAME_MAX - strlen(mytaskfile) - 1);
92f08c3bdfSopenharmony_ci		write_to_file(mytaskfile, "a", getpid());
93f08c3bdfSopenharmony_ci	}
94f08c3bdfSopenharmony_ci
95f08c3bdfSopenharmony_ci	while (1) ;
96f08c3bdfSopenharmony_ci
97f08c3bdfSopenharmony_ci	return 0;
98f08c3bdfSopenharmony_ci}
99