Subversion Repositories shark

Rev

Blame | Last modification | View Log | RSS feed

/*
 * Project: HARTIK (HA-rd R-eal TI-me K-ernel)
 *
 * Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
 *               Gerardo Lamastra <gerardo@sssup.it>
 *
 * Authors     : Paolo Gai <pj@hartik.sssup.it>
 * (see authors.txt for full list of hartik's authors)
 *
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
 *
 * http://www.sssup.it
 * http://retis.sssup.it
 * http://hartik.sssup.it
 */


/**
 ------------
 CVS :        $Id: test5.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $

 File:        $File$
 Revision:    $Revision: 1.1.1.1 $
 Last update: $Date: 2002-09-02 09:37:48 $
 ------------

 Test Number 5:

 this test is a simple main() function with one other task

 This test has to be compiled with init1.c, that introduce 2 RR levels
 with a timeslice of 300us (!)

 This test can be useful to test functions like

 sigemptyset
 sigaddset
 hartik_deliver_pending_signals
 sys_end
 task_sigmask
 sigaction
 sigqueue
 task_signal


**/


/*
 * Copyright (C) 2000 Paolo Gai
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */


#include "kernel/kern.h"


TASK pippo()
{
  struct timespec t;

  do {
    kern_cli();
    ll_gettime(TIME_EXACT, &t);
    kern_sti();

  } while (t.tv_nsec <= 20000000L);
  cli(); kern_printf("pippo"); sti();
  return 0;
}

void catchit(int signo, siginfo_t *info, void *extra)
{
  kern_printf("\nÛ exec_shadow= %d signo=%d code=%d value=%d p=%d Û\n",
            exec_shadow,
            info->si_signo, info->si_code,
            info->si_value.sival_int, info->si_task);
}


void catchit2(int signo)
{
  kern_printf("\nSignal %d: AAARRRRRRGGGGHHHH!!!!\n",signo);
}

int main(int argc, char **argv)
{
  struct timespec t;
  NRT_TASK_MODEL m;
  PID p2;

  sigset_t newmask;
  sigset_t oldmask;
  struct sigaction action;
  union sigval sval;


  /* Set the signal action */
  action.sa_flags = SA_SIGINFO;
  action.sa_sigaction = catchit;
  action.sa_handler = 0;
  action.sa_mask = 0;

  if (sigaction(SIGUSR1, &action, NULL) == -1) {
    perror("Errore");
    return -1;
  }

  action.sa_flags = 0;
  action.sa_handler = catchit2;
// action.sa_sigaction = SIG_DFL;

  if (sigaction(SIGILL, &action, NULL) == -1) {
    perror("Errore");
    return -1;
  }

  /* create another task */
  nrt_task_default_model(m);
  nrt_task_def_level(m,1);
  nrt_task_def_group(m,1);

  p2 = task_create("pippo", pippo, &m, NULL);
  if (p2 == NIL)
  { kern_printf("Can't create pippo task...\n"); return 1; }

  group_activate(1);

  /* block the signal for the main task */
  sigemptyset(&newmask);
  sigaddset(&newmask,SIGUSR1);
  task_sigmask(SIG_BLOCK, &newmask, &oldmask);

  sval.sival_int = 123;
  sigqueue(0,SIGUSR1,sval);
  sval.sival_int = 999;
  sigqueue(0,SIGUSR1,sval);

  cli();kern_printf("\n()()()()\n"); sti();

  task_signal(0 /* main */, SIGILL);

  NULL_TIMESPEC(&t);
  do {
    kern_cli();
    ll_gettime(TIME_EXACT, &t);
    kern_sti();

  } while (t.tv_nsec <= 50000000L);

  cli();kern_printf("\n()*********()\n"); sti();

  return 0;
}