Ejemplo n.º 1
0
    void Scheduler_ut::test_aperiodic_task()
    {
        IPRINTF("\nExecuting %s\n", __func__);
        const units::Nanoseconds test_delay(3 * units::SEC);
        IPRINTF("\nTesting aperiodic tasks. "
                "This test takes at least %" PRId64 " seconds\n",
                int64_t(test_delay / units::SEC));

        /* Create an aperiodic task and make sure it is valid.
         */
        Task_properties task1_props;
        task1_props.prio = higher_priority;
        Test_task task1("aperiodic_1", 5, 3);
        CPPUNIT_ASSERT_EQUAL(true, task1.set_properties(task1_props));
        CPPUNIT_ASSERT_EQUAL(true, task1.is_valid());

        /* Off to the races.
         */
        CPPUNIT_ASSERT_EQUAL(true, task1.start());

        /* Not the most reliable timing method.
         */
        sleep(test_delay);
        task1.stop();

        /* Check the counters to see if the counts match.
         */
        CPPUNIT_ASSERT_EQUAL(3, counter[5]);
    }
Ejemplo n.º 2
0
int
send_metrics(const char *cur, const char *primary, const char *backup, int newrate)
{
	char namebuf1[100], namebuf2[100];
	int ret_val;

	if (cur == primary) {
		snprintf(namebuf1, 100, "%s producer.primary_rate %d", 
			METRIC_SENDER_PATH, newrate);
		snprintf(namebuf2, 100, "%s producer.backup_rate 0", 
			METRIC_SENDER_PATH);
	} else {
		snprintf(namebuf1, 100, "%s producer.backup_rate %d", 
				METRIC_SENDER_PATH, newrate);
		snprintf(namebuf2, 100, "%s producer.primary_rate 0", 
				METRIC_SENDER_PATH);
	}
	ret_val = system(namebuf1);
	if (ret_val < 0) {
		IPRINTF("system() metric sender failed\n");
		return (ret_val);
	}
	ret_val = system(namebuf2);
	if (ret_val < 0) {
		IPRINTF("system() metric sender failed\n");
		return (ret_val);
	}
	return (EXIT_SUCCESS);
}
Ejemplo n.º 3
0
/*
 * Read and validate the Image and Domain headers.
 */
static int read_headers(struct xc_sr_context *ctx)
{
    xc_interface *xch = ctx->xch;
    struct xc_sr_ihdr ihdr;
    struct xc_sr_dhdr dhdr;

    if ( read_exact(ctx->fd, &ihdr, sizeof(ihdr)) )
    {
        PERROR("Failed to read Image Header from stream");
        return -1;
    }

    ihdr.id      = ntohl(ihdr.id);
    ihdr.version = ntohl(ihdr.version);
    ihdr.options = ntohs(ihdr.options);

    if ( ihdr.marker != IHDR_MARKER )
    {
        ERROR("Invalid marker: Got 0x%016"PRIx64, ihdr.marker);
        return -1;
    }
    else if ( ihdr.id != IHDR_ID )
    {
        ERROR("Invalid ID: Expected 0x%08x, Got 0x%08x", IHDR_ID, ihdr.id);
        return -1;
    }
    else if ( ihdr.version != IHDR_VERSION )
    {
        ERROR("Invalid Version: Expected %d, Got %d",
              ihdr.version, IHDR_VERSION);
        return -1;
    }
    else if ( ihdr.options & IHDR_OPT_BIG_ENDIAN )
    {
        ERROR("Unable to handle big endian streams");
        return -1;
    }

    ctx->restore.format_version = ihdr.version;

    if ( read_exact(ctx->fd, &dhdr, sizeof(dhdr)) )
    {
        PERROR("Failed to read Domain Header from stream");
        return -1;
    }

    ctx->restore.guest_type = dhdr.type;
    ctx->restore.guest_page_size = (1U << dhdr.page_shift);

    if ( dhdr.xen_major == 0 )
    {
        IPRINTF("Found %s domain, converted from legacy stream format",
                dhdr_type_to_str(dhdr.type));
        DPRINTF("  Legacy conversion script version %u", dhdr.xen_minor);
    }
    else
        IPRINTF("Found %s domain from Xen %u.%u",
                dhdr_type_to_str(dhdr.type), dhdr.xen_major, dhdr.xen_minor);
    return 0;
}
Ejemplo n.º 4
0
static uint64_t imx_serial_read(void *opaque, target_phys_addr_t offset,
                                unsigned size)
{
    IMXSerialState *s = (IMXSerialState *)opaque;
    uint32_t c;

    DPRINTF("read(offset=%x)\n", offset >> 2);
    switch (offset >> 2) {
    case 0x0: /* URXD */
        c = s->readbuff;
        if (!(s->uts1 & UTS1_RXEMPTY)) {
            /* Character is valid */
            c |= URXD_CHARRDY;
            s->usr1 &= ~USR1_RRDY;
            s->usr2 &= ~USR2_RDR;
            s->uts1 |= UTS1_RXEMPTY;
            imx_update(s);
            qemu_chr_accept_input(s->chr);
        }
        return c;

    case 0x20: /* UCR1 */
        return s->ucr1;

    case 0x21: /* UCR2 */
        return s->ucr2;

    case 0x25: /* USR1 */
        return s->usr1;

    case 0x26: /* USR2 */
        return s->usr2;

    case 0x2A: /* BRM Modulator */
        return s->ubmr;

    case 0x2B: /* Baud Rate Count */
        return s->ubrc;

    case 0x2d: /* Test register */
        return s->uts1;

    case 0x24: /* UFCR */
        return s->ufcr;

    case 0x2c:
        return s->onems;

    case 0x22: /* UCR3 */
        return s->ucr3;

    case 0x23: /* UCR4 */
    case 0x29: /* BRM Incremental */
        return 0x0; /* TODO */

    default:
        IPRINTF("imx_serial_read: bad offset: 0x%x\n", (int)offset);
        return 0;
    }
}
Ejemplo n.º 5
0
    void Scheduler_ut::test_overrun()
    {
        IPRINTF("\nExecuting %s\n", __func__);
        /* Create and run a task that deliberatly causes overruns.
         */
        Task_properties tp;
        tp.prio = 50;
        tp.period = units::Nanoseconds(50 * units::MSEC);
        Overrun_task t("overrun_task");
        CPPUNIT_ASSERT_EQUAL(true, t.is_valid());
        CPPUNIT_ASSERT_EQUAL(true, t.set_properties(tp));

        IPRINTF("\nWe expect a task overrun here\n");
        CPPUNIT_ASSERT_EQUAL(true, t.start());

        /* Run for a little bit. Not the most reliable timing method.
         */
        sleep(units::Nanoseconds(1100 * units::MSEC));
        t.stop();

        /* Set up to read the runtime attributes for this rategroup.
         */
        Runtime_attributes_db &rt_db = Runtime_attributes_db::get_instance();
        Runtime_attributes_db::value_t rt_value;
        char sym_name[SYM_ENTRY_STRLEN + 1];
        snprintf(sym_name, SYM_ENTRY_STRLEN, "%s%" PRId64 "",
                 runtime_attr_symbol_prefix, int64_t(tp.period));
        Runtime_attributes_db::symbol_t *rt_symbol =
            rt_db.lookup_symbol(sym_name);

        /* Make sure that we found the symbol.
         */
        CPPUNIT_ASSERT(rt_symbol);

        /* We should have recorded some overruns.
         */
        CPPUNIT_ASSERT_EQUAL(true, rt_symbol->entry->read(rt_value));
        CPPUNIT_ASSERT(rt_value.max_runtime > tp.period);
#ifdef DEBUG_OVERRUN_BUG
        fprintf(stderr, "UT Num overruns = %u\n", rt_value.num_overruns);
        fprintf(stderr, "UT last runtime = %ld\n",
                int64_t(rt_value.last_runtime));
        fprintf(stderr, "UT max runtime = %ld\n",
                int64_t(rt_value.max_runtime));
#endif
        CPPUNIT_ASSERT(rt_value.num_overruns);
    }
Ejemplo n.º 6
0
static uint64_t imx_gpt_read(void *opaque, hwaddr offset, unsigned size)
{
    IMXGPTState *s = IMX_GPT(opaque);
    uint32_t reg_value = 0;
    uint32_t reg = offset >> 2;

    switch (reg) {
    case 0: /* Control Register */
        reg_value = s->cr;
        break;

    case 1: /* prescaler */
        reg_value = s->pr;
        break;

    case 2: /* Status Register */
        reg_value = s->sr;
        break;

    case 3: /* Interrupt Register */
        reg_value = s->ir;
        break;

    case 4: /* Output Compare Register 1 */
        reg_value = s->ocr1;
        break;

    case 5: /* Output Compare Register 2 */
        reg_value = s->ocr2;
        break;

    case 6: /* Output Compare Register 3 */
        reg_value = s->ocr3;
        break;

    case 7: /* input Capture Register 1 */
        qemu_log_mask(LOG_UNIMP, "icr1 feature is not implemented\n");
        reg_value = s->icr1;
        break;

    case 8: /* input Capture Register 2 */
        qemu_log_mask(LOG_UNIMP, "icr2 feature is not implemented\n");
        reg_value = s->icr2;
        break;

    case 9: /* cnt */
        imx_gpt_update_count(s);
        reg_value = s->cnt;
        break;

    default:
        IPRINTF("Bad offset %x\n", reg);
        break;
    }

    DPRINTF("(%s) = 0x%08x\n", imx_gpt_reg_name(reg), reg_value);

    return reg_value;
}
Ejemplo n.º 7
0
    void Scheduler_ut::test_many_tasks()
    {
        IPRINTF("\nExecuting %s\n", __func__);
        memset(counter, 0, sizeof(counter));

        Test_task *task[NUM_PROCS];

        for(unsigned int i = 0; i < NUM_PROCS; ++i)
        {
            Task_properties task_props;

            /* Allocate each task to one of 10 rate groups.
             */
            task_props.prio = 70 + (i % 10);
            task_props.period =
                (units::Nanoseconds((units::SEC) / ((i % 10) + 1)) /
                 sched_period) *
                sched_period;
            char task_name[20];
            sprintf(task_name, "mtask_%d", i);

            /* Create the tasks and make sure they're valid.
             */
            task[i] = new Test_task(task_name, i);
            CPPUNIT_ASSERT_EQUAL(true, task[i]->set_properties(task_props));
            CPPUNIT_ASSERT_EQUAL(true, task[i]->is_valid());
        }

        for(unsigned int i = 0; i < NUM_PROCS; ++i)
        {
            CPPUNIT_ASSERT_EQUAL(true, task[i]->start());
        }

        sleep(units::Nanoseconds(1 * units::SEC));

        for(unsigned int i = 0; i < NUM_PROCS; ++i)
        {
            /* Since each task should have run for a bit more than one
             * seconds its count should be greater than its frequency, but
             * probably not more than double that.
             */
            units::Nanoseconds period = task[i]->get_period();
            int ex = units::SEC / period;

            char msg[128];
            sprintf(msg,
                    "%s period %" PRId64 ", instance %d ex = %d, actual = %d",
                    task[i]->get_name(), (int64_t)period, i, ex, counter[i]);
            CPPUNIT_ASSERT_MESSAGE(msg, counter[i] >= ex);
            CPPUNIT_ASSERT_MESSAGE(msg, counter[i] < (2 * ex));
            task[i]->stop();
        }

        for(unsigned int i = 0; i < NUM_PROCS; ++i)
        {
            delete task[i];
        }
    }
Ejemplo n.º 8
0
    void Scheduler_ut::test_scheduler()
    {
        IPRINTF("\nExecuting %s\n", __func__);
        Scheduler &sched = Scheduler::get_instance();

        /* The scheduler should start out running schedule 0.
         */
        CPPUNIT_ASSERT_EQUAL((schedule_t)0, sched.get_schedule());
    }
Ejemplo n.º 9
0
    bool Pong::execute()
    {
        /* Read the pong message and output the count.
         */
        if(false == m_ping_subscription->get()) {
            EPRINTF("Error retreiving ping data\n");
        }
        if(m_ping_subscription->was_updated()) {
            IPRINTF("Pong gets %u from ping\n",
                    m_ping_subscription->content.count);
        }

        /* Increment and publish the pong count.
         */
        ++m_pong_publication->content.count;
        IPRINTF("Pong puts %u\n", m_pong_publication->content.count);
        m_pong_publication->put();

        return true;
    }
Ejemplo n.º 10
0
void skip_segment(FILE * movie)
{
   union {
      uint16_t segment_size;
      uint8_t size[2];
   } u;

   /* tokens are followed by the size of their section, on 16bits */
   NEXT_TOKEN(u.size[0]);
   NEXT_TOKEN(u.size[1]);
   CPU_DATA_IS_BIGENDIAN(16, u.segment_size);

   IPRINTF("Skip segment (%d data)\r\n", (unsigned int) u.segment_size);
   SKIP(u.segment_size - 2);
}
Ejemplo n.º 11
0
static uint64_t imx_epit_read(void *opaque, hwaddr offset, unsigned size)
{
    IMXEPITState *s = IMX_EPIT(opaque);
    uint32_t reg_value = 0;
    uint32_t reg = offset >> 2;

    switch (reg) {
    case 0: /* Control Register */
        reg_value = s->cr;
        break;

    case 1: /* Status Register */
        reg_value = s->sr;
        break;

    case 2: /* LR - ticks*/
        reg_value = s->lr;
        break;

    case 3: /* CMP */
        reg_value = s->cmp;
        break;

    case 4: /* CNT */
        imx_epit_update_count(s);
        reg_value = s->cnt;
        break;

    default:
        IPRINTF("Bad offset %x\n", reg);
        break;
    }

    DPRINTF("(%s) = 0x%08x\n", imx_epit_reg_name(reg), reg_value);

    return reg_value;
}
Ejemplo n.º 12
0
static void imx_serial_write(void *opaque, target_phys_addr_t offset,
                      uint64_t value, unsigned size)
{
    IMXSerialState *s = (IMXSerialState *)opaque;
    unsigned char ch;

    DPRINTF("write(offset=%x, value = %x) to %s\n",
            offset >> 2,
            (unsigned int)value, s->chr ? s->chr->label : "NODEV");

    switch (offset >> 2) {
    case 0x10: /* UTXD */
        ch = value;
        if (s->ucr2 & UCR2_TXEN) {
            if (s->chr) {
                qemu_chr_fe_write(s->chr, &ch, 1);
            }
            s->usr1 &= ~USR1_TRDY;
            imx_update(s);
            s->usr1 |= USR1_TRDY;
            imx_update(s);
        }
        break;

    case 0x20: /* UCR1 */
        s->ucr1 = value & 0xffff;
        DPRINTF("write(ucr1=%x)\n", (unsigned int)value);
        imx_update(s);
        break;

    case 0x21: /* UCR2 */
        /*
         * Only a few bits in control register 2 are implemented as yet.
         * If it's intended to use a real serial device as a back-end, this
         * register will have to be implemented more fully.
         */
        if (!(value & UCR2_SRST)) {
            imx_serial_reset(s);
            imx_update(s);
            value |= UCR2_SRST;
        }
        if (value & UCR2_RXEN) {
            if (!(s->ucr2 & UCR2_RXEN)) {
                qemu_chr_accept_input(s->chr);
            }
        }
        s->ucr2 = value & 0xffff;
        break;

    case 0x25: /* USR1 */
        value &= USR1_AWAKE | USR1_AIRINT | USR1_DTRD | USR1_AGTIM |
            USR1_FRAMERR | USR1_ESCF | USR1_RTSD | USR1_PARTYER;
        s->usr1 &= ~value;
        break;

    case 0x26: /* USR2 */
       /*
        * Writing 1 to some bits clears them; all other
        * values are ignored
        */
        value &= USR2_ADET | USR2_DTRF | USR2_IDLE | USR2_ACST |
            USR2_RIDELT | USR2_IRINT | USR2_WAKE |
            USR2_DCDDELT | USR2_RTSF | USR2_BRCD | USR2_ORE;
        s->usr2 &= ~value;
        break;

        /*
         * Linux expects to see what it writes to these registers
         * We don't currently alter the baud rate
         */
    case 0x29: /* UBIR */
        s->ubrc = value & 0xffff;
        break;

    case 0x2a: /* UBMR */
        s->ubmr = value & 0xffff;
        break;

    case 0x2c: /* One ms reg */
        s->onems = value & 0xffff;
        break;

    case 0x24: /* FIFO control register */
        s->ufcr = value & 0xffff;
        break;

    case 0x22: /* UCR3 */
        s->ucr3 = value & 0xffff;
        break;

    case 0x2d: /* UTS1 */
    case 0x23: /* UCR4 */
        IPRINTF("Unimplemented Register %x written to\n", offset >> 2);
        /* TODO */
        break;

    default:
        IPRINTF("imx_serial_write: Bad offset 0x%x\n", (int)offset);
    }
}
Ejemplo n.º 13
0
static int ENOSYS_privcmd_close(xc_interface *xch, xc_osdep_handle h)
{
    IPRINTF(xch, "ENOSYS_privcmd: closing handle %lx\n", h);
    return 0;
}
Ejemplo n.º 14
0
 bool Hello::execute()
 {
     IPRINTF("Hello World\n");
     return (++m_count < m_ntimes);
 }
Ejemplo n.º 15
0
static void imx_epit_write(void *opaque, hwaddr offset, uint64_t value,
                           unsigned size)
{
    IMXEPITState *s = IMX_EPIT(opaque);
    uint32_t reg = offset >> 2;
    uint64_t oldcr;

    DPRINTF("(%s, value = 0x%08x)\n", imx_epit_reg_name(reg), (uint32_t)value);

    switch (reg) {
    case 0: /* CR */

        oldcr = s->cr;
        s->cr = value & 0x03ffffff;
        if (s->cr & CR_SWR) {
            /* handle the reset */
            imx_epit_reset(DEVICE(s));
        } else {
            imx_epit_set_freq(s);
        }

        if (s->freq && (s->cr & CR_EN) && !(oldcr & CR_EN)) {
            if (s->cr & CR_ENMOD) {
                if (s->cr & CR_RLD) {
                    ptimer_set_limit(s->timer_reload, s->lr, 1);
                    ptimer_set_limit(s->timer_cmp, s->lr, 1);
                } else {
                    ptimer_set_limit(s->timer_reload, EPIT_TIMER_MAX, 1);
                    ptimer_set_limit(s->timer_cmp, EPIT_TIMER_MAX, 1);
                }
            }

            imx_epit_reload_compare_timer(s);
            ptimer_run(s->timer_reload, 0);
            if (s->cr & CR_OCIEN) {
                ptimer_run(s->timer_cmp, 0);
            } else {
                ptimer_stop(s->timer_cmp);
            }
        } else if (!(s->cr & CR_EN)) {
            /* stop both timers */
            ptimer_stop(s->timer_reload);
            ptimer_stop(s->timer_cmp);
        } else  if (s->cr & CR_OCIEN) {
            if (!(oldcr & CR_OCIEN)) {
                imx_epit_reload_compare_timer(s);
                ptimer_run(s->timer_cmp, 0);
            }
        } else {
            ptimer_stop(s->timer_cmp);
        }
        break;

    case 1: /* SR - ACK*/
        /* writing 1 to OCIF clear the OCIF bit */
        if (value & 0x01) {
            s->sr = 0;
            imx_epit_update_int(s);
        }
        break;

    case 2: /* LR - set ticks */
        s->lr = value;

        if (s->cr & CR_RLD) {
            /* Also set the limit if the LRD bit is set */
            /* If IOVW bit is set then set the timer value */
            ptimer_set_limit(s->timer_reload, s->lr, s->cr & CR_IOVW);
            ptimer_set_limit(s->timer_cmp, s->lr, 0);
        } else if (s->cr & CR_IOVW) {
            /* If IOVW bit is set then set the timer value */
            ptimer_set_count(s->timer_reload, s->lr);
        }

        imx_epit_reload_compare_timer(s);
        break;

    case 3: /* CMP */
        s->cmp = value;

        imx_epit_reload_compare_timer(s);

        break;

    default:
        IPRINTF("Bad offset %x\n", reg);

        break;
    }
}
Ejemplo n.º 16
0
static void imx_gpt_write(void *opaque, hwaddr offset, uint64_t value,
                          unsigned size)
{
    IMXGPTState *s = IMX_GPT(opaque);
    uint32_t oldreg;
    uint32_t reg = offset >> 2;

    DPRINTF("(%s, value = 0x%08x)\n", imx_gpt_reg_name(reg),
            (uint32_t)value);

    switch (reg) {
    case 0:
        oldreg = s->cr;
        s->cr = value & ~0x7c14;
        if (s->cr & GPT_CR_SWR) { /* force reset */
            /* handle the reset */
            imx_gpt_reset(DEVICE(s));
        } else {
            /* set our freq, as the source might have changed */
            imx_gpt_set_freq(s);

            if ((oldreg ^ s->cr) & GPT_CR_EN) {
                if (s->cr & GPT_CR_EN) {
                    if (s->cr & GPT_CR_ENMOD) {
                        s->next_timeout = GPT_TIMER_MAX;
                        ptimer_set_count(s->timer, GPT_TIMER_MAX);
                        imx_gpt_compute_next_timeout(s, false);
                    }
                    ptimer_run(s->timer, 1);
                } else {
                    /* stop timer */
                    ptimer_stop(s->timer);
                }
            }
        }
        break;

    case 1: /* Prescaler */
        s->pr = value & 0xfff;
        imx_gpt_set_freq(s);
        break;

    case 2: /* SR */
        s->sr &= ~(value & 0x3f);
        imx_gpt_update_int(s);
        break;

    case 3: /* IR -- interrupt register */
        s->ir = value & 0x3f;
        imx_gpt_update_int(s);

        imx_gpt_compute_next_timeout(s, false);

        break;

    case 4: /* OCR1 -- output compare register */
        s->ocr1 = value;

        /* In non-freerun mode, reset count when this register is written */
        if (!(s->cr & GPT_CR_FRR)) {
            s->next_timeout = GPT_TIMER_MAX;
            ptimer_set_limit(s->timer, GPT_TIMER_MAX, 1);
        }

        /* compute the new timeout */
        imx_gpt_compute_next_timeout(s, false);

        break;

    case 5: /* OCR2 -- output compare register */
        s->ocr2 = value;

        /* compute the new timeout */
        imx_gpt_compute_next_timeout(s, false);

        break;

    case 6: /* OCR3 -- output compare register */
        s->ocr3 = value;

        /* compute the new timeout */
        imx_gpt_compute_next_timeout(s, false);

        break;

    default:
        IPRINTF("Bad offset %x\n", reg);
        break;
    }
}
Ejemplo n.º 17
0
    void Scheduler_ut::test_tasks()
    {
        IPRINTF("\nExecuting %s\n", __func__);
        /* Create the tasks.
         */
        Task_properties tprops;
        tprops.period = units::Nanoseconds(20 * units::MSEC);
        tprops.prio = higher_priority;
        Test_task task1("task_2_1", 1);
        CPPUNIT_ASSERT_EQUAL(true, task1.set_properties(tprops));
        CPPUNIT_ASSERT_EQUAL(true, task1.is_valid());

        tprops.prio = lower_priority;
        Test_task task2("task_2_2", 2);
        CPPUNIT_ASSERT_EQUAL(true, task2.set_properties(tprops));
        CPPUNIT_ASSERT_EQUAL(true, task2.is_valid());

        tprops.period = units::Nanoseconds(10 * units::MSEC);
        tprops.prio = highest_priority;
        Test_task task3("task_1_3", 3);
        CPPUNIT_ASSERT_EQUAL(true, task3.set_properties(tprops));
        CPPUNIT_ASSERT_EQUAL(true, task3.is_valid());

        tprops.period = units::Nanoseconds(40 * units::MSEC);
        tprops.prio = lowest_priority;
        Test_task task4("task_4_4", 4);
        CPPUNIT_ASSERT_EQUAL(true, task4.set_properties(tprops));
        CPPUNIT_ASSERT_EQUAL(true, task4.is_valid());

        /* Set up this task with invalid period (faster than the scheduler).
         */
        tprops.period = units::Nanoseconds(sched_period / 2);
        tprops.prio = lowest_priority;
        Test_task task5("task_invalid_period", 5);
        CPPUNIT_ASSERT_EQUAL(true, task5.set_properties(tprops));
        CPPUNIT_ASSERT_EQUAL(true, task5.is_valid());

        /* Runtimes should be zero before the task starts.
         */
        units::Nanoseconds last_runtime = task1.get_last_runtime();
        CPPUNIT_ASSERT_EQUAL(units::Nanoseconds(0), last_runtime);
        CPPUNIT_ASSERT_EQUAL(units::Nanoseconds(0), task1.get_max_runtime());

        /* Off to the races.
         */
        task_terminated = false;
        CPPUNIT_ASSERT_EQUAL(true, task1.start());
        CPPUNIT_ASSERT_EQUAL(true, task2.start());
        CPPUNIT_ASSERT_EQUAL(true, task3.start());
        CPPUNIT_ASSERT_EQUAL(true, task4.start());

        IPRINTF("\nTesting invalid period, an error is expected\n");
        CPPUNIT_ASSERT_EQUAL(false, task5.start());

        /* Not the most reliable timing method.
         */
        sleep(units::Nanoseconds(1 * units::SEC));

        /* Stop the tasks so the counters stop incrementing. This makes
         * cleanup faster too.
         */
        DPRINTF("Halting all test tasks\n");
        DPRINTF("Stopping task 1\n");
        task1.stop();
        DPRINTF("Stopping task 2\n");
        task2.stop();
        DPRINTF("Stopping task 3\n");
        task3.stop();
        DPRINTF("Stopping task 4\n");
        task4.stop();
        CPPUNIT_ASSERT_EQUAL(true, task_terminated);

        /* Check the counters to see if the counts match. Allow some variance
         * to account for the imprecision of halting the task based on a
         * timer.
         */
        CPPUNIT_ASSERT((counter[1] >= 48) && (counter[1] <= 60));
        CPPUNIT_ASSERT((counter[2] >= 48) && (counter[2] <= 60));
        CPPUNIT_ASSERT((counter[3] >= 98) && (counter[3] <= 110));
        CPPUNIT_ASSERT((counter[4] >= 23) && (counter[4] <= 35));

        /* Check that the runtimes are reasonable.
         */
        last_runtime = task1.get_last_runtime();
        IPRINTF("last_runtime = %" PRId64 "\n", int64_t(last_runtime));
        CPPUNIT_ASSERT(last_runtime > units::Nanoseconds(0));
        CPPUNIT_ASSERT(task1.get_max_runtime() >= last_runtime);
    }
Ejemplo n.º 18
0
/*
 * Main Producer Loop
 * ------------------
 */
int
producer(const char *fullTopicName, const char *backupTopicName,
		const char *fname, const char *pipe_fname)
{
	int ret_val;
	char key_content[keySize];
	FILE *fp, *pipe_fp;
	int pipe_fd;
	char *line = NULL;
	size_t len = 0;
	ssize_t read;
	int msg_idx = 0;
	char *linebuf = NULL;
	char *keybuf = NULL;
	struct timeval now, last_now;
	int newrate, rate = STARTING_RATE;
	int n_sent_this_sec = 0;
	long tdiff;
	const char *cur_topic = fullTopicName;
	char namebuf[100];
	streams_topic_partition_t topic;
	streams_config_t config;
	streams_producer_t producer;

	ret_val = producer_init(cur_topic, &topic, &config, &producer);
	if (EXIT_SUCCESS != ret_val) {
		DPRINTF("producer_init() failed\n");
		return (ret_val);
	}

	fp = fopen(fname, "ro");
	if (fp == NULL) {
		DPRINTF("open of file %s failed\n", fname);
		return (-1);
	}
	DPRINTF("opening pipe %s\n", pipe_fname);
	pipe_fd = open(pipe_fname, O_RDWR|O_NONBLOCK);
	if (pipe_fd < 0) {
		DPRINTF("open of file %s failed\n", pipe_fname);
		return (-1);
	}
	pipe_fp = fdopen(pipe_fd, "r");

	DPRINTF("\nSTEP 4: The producer will create, send, "
	    "and flush now\n");

	/* send initial metrics */
	ret_val = send_metrics(cur_topic, fullTopicName, backupTopicName, rate);
	if (EXIT_SUCCESS != ret_val) {
		IPRINTF("send_metrics() failed\n");
		return (ret_val);
	}

	gettimeofday(&last_now, NULL);
	while ((read = getline(&line, &len, fp)) != -1) {
		/*
		 * check if we've sent enough,
		 * if so wait it out so we keep to the specified rate
		 */
		if (n_sent_this_sec >= rate) {

			/* send new metrics */
			ret_val = send_metrics(cur_topic, fullTopicName, backupTopicName, rate);
			if (EXIT_SUCCESS != ret_val) {
				IPRINTF("send_metrics() failed\n");
				return (ret_val);
			}

			gettimeofday(&now, NULL);
			tdiff = tvdiff(&last_now, &now);
			printf("time diff %lu rate %d\n", tdiff, rate);
			if (tdiff < 1000) {
				DPRINTF("produced %d messages in %lums, sleeping\n",
				    rate, tdiff);
				usleep((1000 - tdiff) * 1000);
			} else if (tdiff >= 1000) {
				DPRINTF("warning:  falling behind, took %lums to write"
				    " %d messages\n", tdiff, rate);
			}
			gettimeofday(&last_now, NULL);
			n_sent_this_sec = 0;

			/* check the pipe for a rate change */
			DPRINTF("checking pipe\n");
			ret_val = is_pipe_ready(fileno(pipe_fp));
			if (ret_val < 0) {
				IPRINTF("is_pipe_ready() failed\n");
				return (ret_val);
			}
			if (ret_val > 0) {
				(void) fscanf(pipe_fp, "%d", &newrate);
				IPRINTF("new rate: %d\n", newrate);

				/* if we need to failover, toggle connection to the other cluster */
				if (newrate == FAIL_OVER_CODE || newrate == FAIL_BACK_CODE) {
					IPRINTF("failing over to %s cluster\n",
					    newrate == FAIL_OVER_CODE ? "backup" : "primary");
					ret_val = producer_shutdown(&topic, &config, &producer);
					if (EXIT_SUCCESS != ret_val) {
						DPRINTF("trying to failover: shutdown() failed\n");
						return (ret_val);
					}
					cur_topic =
					    newrate == FAIL_OVER_CODE ? backupTopicName : fullTopicName;
					ret_val = producer_init(cur_topic, &topic, &config, &producer);
					if (EXIT_SUCCESS != ret_val) {
						DPRINTF("trying to failover: init() failed\n");
						return (ret_val);
					}
					/* this was an out-of-band code so leave rate unchanged */
				} else {
					/* this was a rate request, set the new rate to it */
					rate = newrate;

					/* send new metrics */
					ret_val =
					    send_metrics(cur_topic,
					    fullTopicName, backupTopicName, rate);
					if (EXIT_SUCCESS != ret_val) {
						IPRINTF("send_metrics() failed\n");
						return (ret_val);
					}
				}
			}
			continue;
		}
		printf("sending inc %d\n", n_sent_this_sec);
		n_sent_this_sec++;

		/* DPRINTF("Retrieved line of length %zu :\n", read); */
		/* DPRINTF("%s", line); */

		/* Create a unique key and value for each message. */
		char key_content[keySize];
		sprintf(key_content, "Key_%d", msg_idx);

		linebuf = malloc(strlen(line) + 1);
		keybuf = malloc(strlen(key_content) + 1);
		strcpy(keybuf, key_content);
		strcpy(linebuf, line);

		/* Create a record that contains the message. */
		streams_producer_record_t record;
		ret_val = streams_producer_record_create(
		    topic, keybuf, strlen(keybuf) + 1,
		    linebuf, strlen(linebuf) + 1, &record);

		if (EXIT_SUCCESS != ret_val) {
			DPRINTF("streams_producer_record_create() failed\n");
			return (ret_val);
		}

		/* Buffer the message. */
		/* DPRINTF("calling streams_producer_send()\n"); */
		ret_val =
		    streams_producer_send(producer,
		    record, producerCallback, NULL);
	
		if (EXIT_SUCCESS != ret_val) {
			DPRINTF("streams_producer_send() failed\n");
			return (ret_val);
		}
		msg_idx++;
	
		/* Flush the message.
		 * this is the synchronous approach but reduces throughput
		 *
		ret_val = streams_producer_flush(producer);
		if (EXIT_SUCCESS != ret_val) {
			DPRINTF("streams_producer_flush() failed\n");
			return (ret_val);
		}
		DPRINTF("Produced: MESSAGE %d: ", msg_idx);
		*/
	}
	fclose(fp);
	if (line)
		free(line);

	/* send 0 metric now that we're shuttong down */
	ret_val = send_metrics(cur_topic, fullTopicName, backupTopicName, 0);
	if (EXIT_SUCCESS != ret_val) {
		IPRINTF("send_metrics() failed\n");
		return (ret_val);
	}
	return (EXIT_SUCCESS);
}
Ejemplo n.º 19
0
JNIEXPORT void JNICALL Java_net_yolosec_upckeygen_algorithms_UpcKeygen_upcUbeeSsidFind
        (JNIEnv * env, jobject obj, jbyteArray ess)
{
  // Get stopRequested - cancellation flag.
  jclass cls = (*env)->GetObjectClass(env, obj);
  jfieldID fid_s = (*env)->GetFieldID(env, cls, "stopRequested", "Z");
  if (fid_s == NULL) {
    return; /* exception already thrown */
  }
  unsigned char stop = (*env)->GetBooleanField(env, obj, fid_s);

  // Monitoring methods
  jmethodID on_key_computed = (*env)->GetMethodID(env, cls, "onKeyComputed", "(Ljava/lang/String;Ljava/lang/String;II)V");
  jmethodID on_progressed = (*env)->GetMethodID(env, cls, "onProgressed", "(D)V");
  if (on_key_computed == NULL || on_progressed == NULL){
    return;
  }

  // ESSID reading from parameter.
  jbyte *e_native = (*env)->GetByteArrayElements(env, ess, 0);
  jsize e_ssid_len = (*env)->GetArrayLength(env, ess);
  char * e_ssid = (char*) e_native;

  IPRINTF("Computing UPC UBEE keys for essid [%.*s]", e_ssid_len, e_ssid);
  unsigned long stop_ctr = 0;
  unsigned long iter_ctr = 0;
  unsigned char mac[] = {0x64, 0x7c, 0x34, 0x0, 0x0, 0x0};
  unsigned char ssid_cmp[12];
  unsigned char pass[12] = {0,0,0,0,0,0,0,0,0,0,0,0};
  char mac_str[20];
  uint32_t buf[3];
  int cnt = 0;
  const long MAX_ITERATIONS_UBEE = 16777216;

  // Compute - from upc_keys.c
  for (buf[0] = 0; buf[0] <= 0xff; buf[0]++) {
    for (buf[1] = 0; buf[1] <= 0xff; buf[1]++) {
      for (buf[2] = 0; buf[2] <= 0xff; buf[2]++) {
          // Check cancellation signal & progress monitoring.
          stop_ctr += 1;
          iter_ctr += 1;
          if (stop_ctr > (MAX_ITERATIONS_UBEE/2000)){
            stop_ctr = 0;
            stop = (*env)->GetBooleanField(env, obj, fid_s);
            if (stop) {
              break;
            }

            double current_progress = (double)iter_ctr / MAX_ITERATIONS_UBEE;
            (*env)->CallVoidMethod(env, obj, on_progressed, (jdouble)current_progress);
          }

          mac[3] = buf[0];
          mac[4] = buf[1];
          mac[5] = buf[2];
          ubee_generate_ssid(mac, ssid_cmp, NULL);
          if ((unsigned)ssid_cmp[3] == (unsigned)e_ssid[3]
           && (unsigned)ssid_cmp[4] == (unsigned)e_ssid[4]
           && (unsigned)ssid_cmp[5] == (unsigned)e_ssid[5]
           && (unsigned)ssid_cmp[6] == (unsigned)e_ssid[6]
           && (unsigned)ssid_cmp[7] == (unsigned)e_ssid[7]
           && (unsigned)ssid_cmp[8] == (unsigned)e_ssid[8]
           && (unsigned)ssid_cmp[9] == (unsigned)e_ssid[9])
         {
           cnt++;
           ubee_generate_pass(mac, pass, NULL);
           sprintf(mac_str, "64:7c:34:%02x:%02x:%02x", mac[3], mac[4], mac[5]);

           IPRINTF("  -> #%02d WPA2 UBEE phrase for SSID '%.*s' pass '%s', mac %s",
             cnt, e_ssid_len, e_ssid, pass, mac_str);

           jstring jpass = (*env)->NewStringUTF(env, pass);
           jstring jmac = (*env)->NewStringUTF(env, mac_str);
           (*env)->CallVoidMethod(env, obj, on_key_computed, jpass, jmac, (jint)0, (jint)0);
           (*env)->DeleteLocalRef(env, jpass);
           (*env)->DeleteLocalRef(env, jmac);
         }
      }
    }
  }
}
Ejemplo n.º 20
0
static xc_osdep_handle ENOSYS_privcmd_open(xc_interface *xch)
{
    IPRINTF(xch, "ENOSYS_privcmd: opening handle %d\n", 1);
    return (xc_osdep_handle)1; /*dummy*/
}
Ejemplo n.º 21
0
    void Scheduler_ut::test_schedules()
    {
        IPRINTF("\nExecuting %s\n", __func__);
        Task_db::value_t task_props;
        Scheduler &sched = Scheduler::get_instance();
#if 0

        /* Halt the scheduler.
         */
        sched.stop();

        /* Store the task properties.
         */
        task_props.prio = 98;
        task_props.period = sched_period;

        CPPUNIT_ASSERT_EQUAL(true, sched.set_properties(task_props));
#endif

        CPPUNIT_ASSERT_EQUAL((unsigned)0, sched.get_schedule());

        for(schedule_t i = 0; i < 32; ++i)
        {
            sched.set_schedule(i);
            CPPUNIT_ASSERT_EQUAL(i, sched.get_schedule());
        }

        /* Create the tasks and make sure they're valid.
         */
        task_props.period = units::Nanoseconds(20 * units::MSEC);
        task_props.prio = higher_priority;
        task_props.schedule_presence = 0x000A; // 1010
        Test_task task1("task_1", 1);
        CPPUNIT_ASSERT_EQUAL(true, task1.set_properties(task_props));
        CPPUNIT_ASSERT_EQUAL(true, task1.is_valid());

        task_props.prio = lower_priority;
        task_props.schedule_presence = 0x000D; // 1101
        Test_task task2("task_2", 2);
        CPPUNIT_ASSERT_EQUAL(true, task2.set_properties(task_props));
        CPPUNIT_ASSERT_EQUAL(true, task2.is_valid());

        sched.set_schedule(31);

        /* Off to the races.
         */
        CPPUNIT_ASSERT_EQUAL(true, task1.start());
        CPPUNIT_ASSERT_EQUAL(true, task2.start());
        // CPPUNIT_ASSERT_EQUAL(true, sched.start());

        IPRINTF("\nTesting multiple schedules.\n"
                "This test will take at least 4 seconds to complete.\n");
        for(int i = 0; i < 4; ++i)
        {
            sched.set_schedule(i);

            /* Not the most reliable timing method.
             */
            sleep(units::Nanoseconds(1 * units::SEC));

            sched.set_schedule(31);

            /* Check the counters to see if the counts match. Allow some
             * variance to account for the imprecision of halting the task
             * based on a timer.
             */
            if(task1.is_present_in_schedule(i))
            {
                CPPUNIT_ASSERT((counter[1] >= 48) && (counter[1] <= 60));
            }
            else
            {
                CPPUNIT_ASSERT_EQUAL(0, counter[1]);
            }

            if(task2.is_present_in_schedule(i))
            {
                CPPUNIT_ASSERT((counter[2] >= 48) && (counter[2] <= 60));
            }
            else
            {
                CPPUNIT_ASSERT_EQUAL(0, counter[2]);
            }

            counter[1] = 0;
            counter[2] = 0;
        }

        DPRINTF("Halting all test tasks\n");
        DPRINTF("Stopping task 1\n");
        task1.stop();
        DPRINTF("Stopping task 2\n");
        task2.stop();

        sched.set_schedule(0);
        CPPUNIT_ASSERT_EQUAL((unsigned)0, sched.get_schedule());
    }
Ejemplo n.º 22
0
JNIEXPORT void JNICALL Java_net_yolosec_upckeygen_algorithms_UpcKeygen_upcNative
        (JNIEnv * env, jobject obj, jbyteArray ess, jint mode)
{
  // Get stopRequested - cancellation flag.
  jclass cls = (*env)->GetObjectClass(env, obj);
  jfieldID fid_s = (*env)->GetFieldID(env, cls, "stopRequested", "Z");
  if (fid_s == NULL) {
    return; /* exception already thrown */
  }
  unsigned char stop = (*env)->GetBooleanField(env, obj, fid_s);

  // Monitoring methods
  jmethodID on_key_computed = (*env)->GetMethodID(env, cls, "onKeyComputed", "(Ljava/lang/String;Ljava/lang/String;II)V");
  jmethodID on_progressed = (*env)->GetMethodID(env, cls, "onProgressed", "(D)V");
  if (on_key_computed == NULL || on_progressed == NULL){
    return;
  }

  // ESSID reading from parameter.
  jbyte *e_native = (*env)->GetByteArrayElements(env, ess, 0);
  jsize e_ssid_len = (*env)->GetArrayLength(env, ess);
  char * e_ssid = (char*) e_native;
  char e_ssid_nullterm[24];
  strncpy(e_ssid_nullterm, e_ssid, e_ssid_len);

  // Definitions.
  int matched[2], mx;
  uint32_t buf[4], target;
  char serial[64];
  char pass[9];
  const char * serial_prefixes[] = { "SAAP", "SAPP", "SBAP" };
  const int prefixes_cnt = (sizeof(serial_prefixes)/sizeof(serial_prefixes[0]));
  uint32_t i, cnt=0, pidx;

  target = strtoul(e_ssid_nullterm + 3, NULL, 0);
  IPRINTF("Computing UPC keys for essid [%s], target %lu, mode: %d, ssid len: %d", e_ssid_nullterm, (unsigned long)target, mode, (int)e_ssid_len);
  unsigned long stop_ctr = 0;
  unsigned long iter_ctr = 0;

  // Compute - from upc_keys.c
  for (buf[0] = 0; buf[0] <= MAX0; buf[0]++) {
    for (buf[1] = 0; buf[1] <= MAX1; buf[1]++) {
      for (buf[2] = 0; buf[2] <= MAX2; buf[2]++) {
        for (buf[3] = 0; buf[3] <= MAX3; buf[3]++) {
          // Check cancellation signal & progress monitoring.
          stop_ctr += 1;
          iter_ctr += 1;
          if (stop_ctr > (MAX_ITERATIONS/2000)){
            stop_ctr = 0;
            stop = (*env)->GetBooleanField(env, obj, fid_s);
            if (stop) {
              break;
            }

            double current_progress = (double)iter_ctr / MAX_ITERATIONS;
            (*env)->CallVoidMethod(env, obj, on_progressed, (jdouble)current_progress);
          }

          matched[0]= (mode & 1) && upc_generate_ssid(buf, MAGIC_24GHZ) == target;
          matched[1]= (mode & 2) && upc_generate_ssid(buf, MAGIC_5GHZ) == target;
          if (!matched[0] && !matched[1]){
            continue;
          }

          for(pidx=0; pidx < prefixes_cnt; ++pidx){
            sprintf(serial, "%s%d%02d%d%04d", serial_prefixes[pidx], buf[0], buf[1], buf[2], buf[3]);

            // For matched mode compute passwords.
            for(mx=0; mx<2; mx++){
              if (matched[mx]==0){
                continue;
              }

              cnt++;
              compute_wpa2(mx+1, serial, pass);
              IPRINTF("  -> #%02d WPA2 phrase for '%s' = '%s', mode: %d", cnt, serial, pass, mx+1);

              jstring jpass = (*env)->NewStringUTF(env, pass);
              jstring jserial = (*env)->NewStringUTF(env, serial);
              (*env)->CallVoidMethod(env, obj, on_key_computed, jpass, jserial, (jint)mx+1, (jint)0);
              (*env)->DeleteLocalRef(env, jpass);
              (*env)->DeleteLocalRef(env, jserial);
            }
          }
        }
      }
    }
  }
}