]> wirehaze git hosting - ppos.git/blob - ppos/test/pingpong-contab.c

wirehaze git hosting

tasks implementation (ongoing)
[ppos.git] / ppos / test / pingpong-contab.c
1 // PingPongOS - PingPong Operating System
2 // Prof. Carlos A. Maziero, DINF UFPR
3 // Versão 2.0 -- Junho de 2025
4
5 // ATENÇÃO: ESTE ARQUIVO NÃO DEVE SER ALTERADO;
6 // ALTERAÇÕES SERÃO DESCARTADAS NA CORREÇÃO.
7
8 // Teste da contabilização com tarefas de prioridades iguais
9
10 #include <assert.h>
11 #include "lib/libc.h"
12 #include "ppos.h"
13
14 #define WORKLOAD 40000
15
16 static struct task_t *pang, *peng, *ping, *pong, *pung;
17
18 // simula um processamento pesado
19 int hardwork(int n)
20 {
21 int soma = 0;
22
23 for (int i = 0; i < n; i++)
24 for (int j = 0; j < n; j++)
25 soma += j;
26 return (soma);
27 }
28
29 // corpo das tarefas
30 void body(void *arg)
31 {
32 printf("%5d ms: %s inicia\n", systime(), (char *)arg);
33 hardwork(WORKLOAD);
34 printf("%5d ms: %s termina\n", systime(), (char *)arg);
35 task_exit(0);
36 }
37
38 // corpo da tarefa principal
39 void user_main(void *arg)
40 {
41 printf("user: inicio\n");
42
43 // cria tarefas
44 pang = task_create("pang", body, "\tPang");
45 assert(pang);
46 peng = task_create("peng", body, "\t\tPeng");
47 assert(peng);
48 ping = task_create("ping", body, "\t\t\tPing");
49 assert(ping);
50 pong = task_create("pong", body, "\t\t\t\tPong");
51 assert(pong);
52 pung = task_create("pung", body, "\t\t\t\t\tPung");
53 assert(pung);
54
55 printf("user: fim\n");
56
57 task_exit(0);
58 }