Exemple #1
0
static int
suspend_test_helper_2a(seL4_CPtr *t1, seL4_CPtr *t2a, seL4_CPtr *t2b)
{
    /* Helper function that runs at a higher priority. */

    /* Start here. */
    CHECK_STEP(suspend_test_step, 0);

    /* Wait for a timer tick to make 2b run. */
    while (suspend_test_step == 1)
        /* spin */{
        ;
    }

    /* Suspend helper 2b. */
    int error = seL4_TCB_Suspend(*t2b);
    test_check(!error);

    CHECK_STEP(suspend_test_step, 2);

    /* Now suspend ourselves, passing control to the low priority process to
     * resume 2b. */
    error = seL4_TCB_Suspend(*t2a);
    test_check(!error);

    return sel4test_get_result();
}
Exemple #2
0
static VALUE rb_gsl_odeiv_evolve_apply(VALUE obj, VALUE cc, VALUE ss, VALUE sss,
				       VALUE tt, VALUE tt1, VALUE hh, VALUE yy)
{
  gsl_odeiv_evolve *e = NULL;
  gsl_odeiv_control *c = NULL;
  gsl_odeiv_step *s = NULL;
  gsl_odeiv_system *sys = NULL;
  gsl_vector *y = NULL;
  double t, h;
  int status;
  CHECK_STEP(ss); CHECK_SYSTEM(sss);
  CHECK_VECTOR(yy);
  Data_Get_Struct(obj, gsl_odeiv_evolve, e);
  if (NIL_P(cc)) {
    c = NULL;
  } else {
    CHECK_CONTROL(cc); 
    Data_Get_Struct(cc, gsl_odeiv_control, c);
  }
  Data_Get_Struct(ss, gsl_odeiv_step, s);
  Data_Get_Struct(sss, gsl_odeiv_system, sys);
  Data_Get_Struct(yy, gsl_vector, y);
  /*  if (TYPE(tt) != T_FLOAT) rb_raise(rb_eTypeError, "argument 4 Float expected");
      if (TYPE(hh) != T_FLOAT) rb_raise(rb_eTypeError, "argument 6 Float expected");*/
  t = NUM2DBL(tt);
  h = NUM2DBL(hh);
  status = gsl_odeiv_evolve_apply(e, c, s, sys, &t, NUM2DBL(tt1), &h, y->data);
  /*  RFLOAT(tt)->value = t;
      RFLOAT(hh)->value = h;*/
  return rb_ary_new3(3, rb_float_new(t), rb_float_new(h), INT2FIX(status));
}
int PinnedMediaDBManager::insertPinnedMediaItem(const std::string& path, const std::string& object_id, u64 device_id)
{
    int rv = 0;
    int rc;
    static const char* SQL_UPDATE_PINNED_MEDIA_ITEM =
            "INSERT OR REPLACE INTO pin_item (path,"
                                             "object_id,"
                                             "device_id) "
            "VALUES (?,?,?)";
    sqlite3_stmt *stmt = NULL;

    CHECK_DB_HANDLE(rv, m_db, end);

    rc = sqlite3_prepare_v2(m_db, SQL_UPDATE_PINNED_MEDIA_ITEM, -1, &stmt, NULL);
    CHECK_PREPARE(rv, rc, SQL_UPDATE_PINNED_MEDIA_ITEM, m_db, end);

    rc = sqlite3_bind_text(stmt, 1, path.c_str(), -1, SQLITE_STATIC);
    CHECK_BIND(rv, rc, m_db, end);

    rc = sqlite3_bind_text(stmt, 2, object_id.c_str(), -1, SQLITE_STATIC);
    CHECK_BIND(rv, rc, m_db, end);

    rc = sqlite3_bind_int64(stmt, 3, device_id);
    CHECK_BIND(rv, rc, m_db, end);

    rc = sqlite3_step(stmt);
    CHECK_STEP(rv, rc, m_db, end);

end:
    FINALIZE_STMT(rv, rc, m_db, stmt);
    return rv;
}
int PinnedMediaDBManager::getSchemaVersion(u64& version)
{
    int rv = 0;
    int rc;
    int sql_type;
    static const char* SQL_GET_SCHEMA_VERSION_FROM_DB_ATTR =
            "SELECT id, value "
            "FROM db_attr "
            "WHERE id="XSTR(KEY_SCHEMA_VERSION);
    sqlite3_stmt *stmt = NULL;

    CHECK_DB_HANDLE(rv, m_db, end);

    rc = sqlite3_prepare_v2(m_db, SQL_GET_SCHEMA_VERSION_FROM_DB_ATTR, -1, &stmt, NULL);
    CHECK_PREPARE(rv, rc, SQL_GET_SCHEMA_VERSION_FROM_DB_ATTR, m_db, end);

    rc = sqlite3_step(stmt);
    CHECK_STEP(rv, rc, m_db, end);
    CHECK_ROW_EXIST(rv, rc, m_db, end);

    sql_type = sqlite3_column_type(stmt, 1);
    if (sql_type == SQLITE_INTEGER) {
        version = sqlite3_column_int64(stmt, 1);
    } else {
        LOG_WARN("Bad column type index: %d", 1);
        rv = -1;
        goto end;
    }

end:
    FINALIZE_STMT(rv, rc, m_db, stmt);
    return rv;
}
Exemple #5
0
static int
test_suspend(struct env* env)
{
    helper_thread_t thread1;
    helper_thread_t thread2a;
    helper_thread_t thread2b;

    ZF_LOGD("Starting test_suspend\n");

    create_helper_thread(env, &thread1);
    ZF_LOGD("Show me\n");
    create_helper_thread(env, &thread2a);

    create_helper_thread(env, &thread2b);

    /* First set all the helper threads to have unique priorities
     * and then start them in order of priority. This is so when
     * the 'start_helper' function does an IPC to the helper
     * thread, it doesn't allow one of the already started helper
     * threads to run at all */
    set_helper_priority(&thread1, 0);
    set_helper_priority(&thread2a, 1);
    set_helper_priority(&thread2b, 2);

    start_helper(env, &thread1, (helper_fn_t) suspend_test_helper_1,
                 (seL4_Word) &thread1.thread.tcb.cptr,
                 (seL4_Word) &thread2a.thread.tcb.cptr,
                 (seL4_Word) &thread2b.thread.tcb.cptr, 0);

    start_helper(env, &thread2a, (helper_fn_t) suspend_test_helper_2a,
                 (seL4_Word) &thread1.thread.tcb.cptr,
                 (seL4_Word) &thread2a.thread.tcb.cptr,
                 (seL4_Word) &thread2b.thread.tcb.cptr, 0);

    start_helper(env, &thread2b, (helper_fn_t) suspend_test_helper_2b,
                 (seL4_Word) &thread1.thread.tcb.cptr,
                 (seL4_Word) &thread2a.thread.tcb.cptr,
                 (seL4_Word) &thread2b.thread.tcb.cptr, 0);

    /* Now set their priorities to what we want */
    set_helper_priority(&thread1, 100);
    set_helper_priority(&thread2a, 101);
    set_helper_priority(&thread2b, 101);

    suspend_test_step = 0;
    ZF_LOGD("      ");

    wait_for_helper(&thread1);
    wait_for_helper(&thread2b);

    CHECK_STEP(suspend_test_step, 6);
    ZF_LOGD("\n");

    cleanup_helper(env, &thread1);
    cleanup_helper(env, &thread2a);
    cleanup_helper(env, &thread2b);

    return sel4test_get_result();
}
Exemple #6
0
static int
test_ipc_prios(struct env* env)
{
    vka_t *vka = &env->vka;
    helper_thread_t thread0;
    helper_thread_t thread1;
    helper_thread_t thread2;
    helper_thread_t thread3;
    int result = 0;

    ipc_test_data_t data;
    memset(&data, 0, sizeof(data));

    data.ep0 = vka_alloc_endpoint_leaky(vka);
    data.ep1 = vka_alloc_endpoint_leaky(vka);
    data.ep2 = vka_alloc_endpoint_leaky(vka);
    data.ep3 = vka_alloc_endpoint_leaky(vka);

    create_helper_thread(env, &thread0);
    set_helper_priority(&thread0, 0);

    create_helper_thread(env, &thread1);
    set_helper_priority(&thread1, 1);

    create_helper_thread(env, &thread2);
    set_helper_priority(&thread2, 2);

    create_helper_thread(env, &thread3);
    set_helper_priority(&thread3, 3);

    data.tcb0 = thread0.thread.tcb.cptr;
    data.tcb1 = thread1.thread.tcb.cptr;
    data.tcb2 = thread2.thread.tcb.cptr;
    data.tcb3 = thread3.thread.tcb.cptr;

    ZF_LOGD("      ");
    ipc_test_step = 0;

    start_helper(env, &thread0, (helper_fn_t) ipc_test_helper_0, (seL4_Word) &data, 0, 0, 0);
    start_helper(env, &thread1, (helper_fn_t) ipc_test_helper_1, (seL4_Word) &data, 0, 0, 0);
    start_helper(env, &thread2, (helper_fn_t) ipc_test_helper_2, (seL4_Word) &data, 0, 0, 0);
    start_helper(env, &thread3, (helper_fn_t) ipc_test_helper_3, (seL4_Word) &data, 0, 0, 0);

    result |= (int)wait_for_helper(&thread1);
    result |= (int)wait_for_helper(&thread3);

    CHECK_STEP(ipc_test_step, 10);
    ZF_LOGD("\n");

    cleanup_helper(env, &thread0);
    cleanup_helper(env, &thread1);
    cleanup_helper(env, &thread2);
    cleanup_helper(env, &thread3);

    return result;
}
Exemple #7
0
static VALUE rb_gsl_odeiv_solver_set_step(VALUE obj, VALUE ss)
{
  gsl_odeiv_solver *gos = NULL;
  gsl_odeiv_step *s = NULL;
  CHECK_STEP(ss);
  Data_Get_Struct(obj, gsl_odeiv_solver, gos);
  Data_Get_Struct(ss, gsl_odeiv_step, s);
  gos->s = s;
  return obj;
}
Exemple #8
0
static int
suspend_test_helper_2b(seL4_CPtr *t1, seL4_CPtr *t2a, seL4_CPtr *t2b)
{
    /* Wait for 2a to get suspend_test_step set to 1. */
    test_check(suspend_test_step == 0 || suspend_test_step == 1);
    while (suspend_test_step == 0) {
        seL4_Yield();
    }

    /* Timer tick should bring us back here. */
    CHECK_STEP(suspend_test_step, 1);

    /* Now spin and wait for us to be suspended. */
    while (suspend_test_step == 2) {
        seL4_Yield();
    }

    /* When we wake up suspend_test_step should be 4. */
    CHECK_STEP(suspend_test_step, 4);

    return sel4test_get_result();
}
Exemple #9
0
static int
ipc_test_helper_1(ipc_test_data_t *data)
{
    seL4_Word sender_badge = 0;
    seL4_MessageInfo_t tag;
    int result = 0;

    /* TEST PART 1 */
    /* Receive a pending send. */
    CHECK_STEP(ipc_test_step, 1);
    tag = seL4_Recv(data->ep1, &sender_badge);

    /* As soon as the wait is performed, we should be preempted. */

    /* Thread 3 will give us a chance to check our message. */
    CHECK_STEP(ipc_test_step, 3);
    CHECK_TESTCASE(result, seL4_MessageInfo_get_length(tag) == 20);
    for (int i = 0; i < seL4_MessageInfo_get_length(tag); i++) {
        CHECK_TESTCASE(result, seL4_GetMR(i) == i);
    }

    /* Now we bounce to allow thread 3 control again. */
    seL4_MessageInfo_ptr_set_length(&tag, 0);
    seL4_Call(data->ep0, tag);

    /* TEST PART 2 */
    /* Receive a send that is not yet pending. */
    CHECK_STEP(ipc_test_step, 5);
    tag = seL4_Recv(data->ep1, &sender_badge);

    CHECK_STEP(ipc_test_step, 8);
    CHECK_TESTCASE(result, seL4_MessageInfo_get_length(tag) == 19);
    for (int i = 0; i < seL4_MessageInfo_get_length(tag); i++) {
        CHECK_TESTCASE(result, seL4_GetMR(i) == i);
    }

    return result;
}
Exemple #10
0
static int
suspend_test_helper_1(seL4_CPtr *t1, seL4_CPtr *t2a, seL4_CPtr *t2b)
{
    CHECK_STEP(suspend_test_step, 3);

    /* Our sole job is to wake up 2b. */
    int error = seL4_TCB_Resume(*t2b);
    test_check(!error);

    /* We should have been preempted immediately, so by the time we run again,
     * the suspend_test_step should be 5. */

#if 1 // WE HAVE A BROKEN SCHEDULER IN SEL4
    /* FIXME: The seL4 scheduler is broken, and seL4_TCB_Resume will not
     * preempt. The only way to get preempted is to force it ourselves (or wait
     * for a timer tick). */
    seL4_Yield();
#endif

    CHECK_STEP(suspend_test_step, 5);

    return sel4test_get_result();
}
int PinnedMediaDBManager::commitTransaction()
{
    int rv = 0;
    int rc;
    static const char* SQL_COMMIT = "COMMIT";
    sqlite3_stmt *stmt = NULL;

    CHECK_DB_HANDLE(rv, m_db, end);

    rc = sqlite3_prepare_v2(m_db, SQL_COMMIT, -1, &stmt, NULL);
    CHECK_PREPARE(rv, rc, SQL_COMMIT, m_db, end);

    rc = sqlite3_step(stmt);
    CHECK_STEP(rv, rc, m_db, end);

 end:
    FINALIZE_STMT(rv, rc, m_db, stmt);
    return rv;
}
int PinnedMediaDBManager::beginTransaction()
{
    int rv = 0;
    int rc;
    static const char* SQL_BEGIN = "BEGIN IMMEDIATE";
    sqlite3_stmt *stmt = NULL;

    CHECK_DB_HANDLE(rv, m_db, end);

    rc = sqlite3_prepare_v2(m_db, SQL_BEGIN, -1, &stmt, NULL);
    CHECK_PREPARE(rv, rc, SQL_BEGIN, m_db, end);

    rc = sqlite3_step(stmt);
    CHECK_STEP(rv, rc, m_db, end);

 end:
    FINALIZE_STMT(rv, rc, m_db, stmt);
    return rv;
}
int PinnedMediaDBManager::deleteAllPinnedMediaItems()
{
    int rv = 0;
    int rc;
    static const char* SQL_DELETE_ALL_PINNED_MEDIA_ITEMS =
            "DELETE FROM pin_item";
    sqlite3_stmt *stmt = NULL;

    CHECK_DB_HANDLE(rv, m_db, end);

    rc = sqlite3_prepare_v2(m_db, SQL_DELETE_ALL_PINNED_MEDIA_ITEMS, -1, &stmt, NULL);
    CHECK_PREPARE(rv, rc, SQL_DELETE_ALL_PINNED_MEDIA_ITEMS, m_db, end);

    rc = sqlite3_step(stmt);
    CHECK_STEP(rv, rc, m_db, end);

end:
    FINALIZE_STMT(rv, rc, m_db, stmt);
    return rv;
}
int PinnedMediaDBManager::deleteAllRelatedPinnedMediaItems(u64 device_id)
{
    int rv = 0;
    int rc;
    static const char* SQL_DELETE_PINNED_MEDIA_ITEM_BY_DEVICE_ID =
            "DELETE FROM pin_item WHERE device_id=?";
    sqlite3_stmt *stmt = NULL;

    CHECK_DB_HANDLE(rv, m_db, end);

    rc = sqlite3_prepare_v2(m_db, SQL_DELETE_PINNED_MEDIA_ITEM_BY_DEVICE_ID, -1, &stmt, NULL);
    CHECK_PREPARE(rv, rc, SQL_DELETE_PINNED_MEDIA_ITEM_BY_DEVICE_ID, m_db, end);

    rc = sqlite3_bind_int64(stmt, 1, device_id);
    CHECK_BIND(rv, rc, m_db, end);

    rc = sqlite3_step(stmt);
    CHECK_STEP(rv, rc, m_db, end);

end:
    FINALIZE_STMT(rv, rc, m_db, stmt);
    return rv;
}
int PinnedMediaDBManager::deletePinnedMediaItem(const std::string& path)
{
    int rv = 0;
    int rc;
    static const char* SQL_DELETE_PINNED_MEDIA_ITEM_BY_PATH =
            "DELETE FROM pin_item WHERE path=?";
    sqlite3_stmt *stmt = NULL;

    CHECK_DB_HANDLE(rv, m_db, end);

    rc = sqlite3_prepare_v2(m_db, SQL_DELETE_PINNED_MEDIA_ITEM_BY_PATH, -1, &stmt, NULL);
    CHECK_PREPARE(rv, rc, SQL_DELETE_PINNED_MEDIA_ITEM_BY_PATH, m_db, end);

    rc = sqlite3_bind_text(stmt, 1, path.c_str(), -1, SQLITE_STATIC);
    CHECK_BIND(rv, rc, m_db, end);

    rc = sqlite3_step(stmt);
    CHECK_STEP(rv, rc, m_db, end);

end:
    FINALIZE_STMT(rv, rc, m_db, stmt);
    return rv;
}
int PinnedMediaDBManager::selectPinnedMediaItem(const std::string& object_id, u64 device_id, PinnedMediaItem& output_pinned_media_item)
{
    int rv = 0;
    int rc;
    static const char* SQL_SELECT_PINNED_MEDIA_ITEM_BY_OBJECT_ID_AND_DEVICE_ID =
            "SELECT path, object_id, device_id "
            "FROM pin_item "
            "WHERE object_id=? AND device_id=?";
    sqlite3_stmt *stmt = NULL;

    CHECK_DB_HANDLE(rv, m_db, end);

    rc = sqlite3_prepare_v2(m_db, SQL_SELECT_PINNED_MEDIA_ITEM_BY_OBJECT_ID_AND_DEVICE_ID, -1, &stmt, NULL);
    CHECK_PREPARE(rv, rc, SQL_SELECT_PINNED_MEDIA_ITEM_BY_OBJECT_ID_AND_DEVICE_ID, m_db, end);

    rc = sqlite3_bind_text(stmt, 1, object_id.c_str(), -1, SQLITE_STATIC);
    CHECK_BIND(rv, rc, m_db, end);

    rc = sqlite3_bind_int64(stmt, 2, device_id);
    CHECK_BIND(rv, rc, m_db, end);

    {
        std::string path;
        std::string object_id;
        u64 device_id;
        int sql_type;
        rc = sqlite3_step(stmt);
        CHECK_STEP(rv, rc, m_db, end);
        CHECK_ROW_EXIST(rv, rc, m_db, end);

        sql_type = sqlite3_column_type(stmt, 0);
        if (sql_type == SQLITE_TEXT) {
            path = reinterpret_cast<const char*>(sqlite3_column_text(stmt, 0));
        } else {
            LOG_WARN("Bad column type index: %d", 0);
            rv = -1;
            goto end;
        }

        sql_type = sqlite3_column_type(stmt, 1);
        if (sql_type == SQLITE_TEXT) {
            object_id = reinterpret_cast<const char*>(sqlite3_column_text(stmt, 1));
        } else {
            LOG_WARN("Bad column type index: %d", 1);
            rv = -1;
            goto end;
        }

        sql_type = sqlite3_column_type(stmt, 2);
        if (sql_type == SQLITE_INTEGER) {
            device_id = sqlite3_column_int64(stmt, 2);
        } else {
            LOG_WARN("Bad column type index: %d", 2);
            rv = -1;
            goto end;
        }

        output_pinned_media_item.path = path;
        output_pinned_media_item.object_id = object_id;
        output_pinned_media_item.device_id = device_id;
    }

end:
    FINALIZE_STMT(rv, rc, m_db, stmt);
    return rv;
}
Exemple #17
0
static int
ipc_test_helper_3(ipc_test_data_t *data)
{
    seL4_MessageInfo_t tag;
    int last_spins, last_bounces, result = 0;

    /* This test starts here. */

    /* TEST PART 1 */
    /* Perform a send to a thread 1. It is not yet waiting. */
    CHECK_STEP(ipc_test_step, 0);
    seL4_MessageInfo_ptr_new(&tag, 0, 0, 0, 20);
    for (int i = 0; i < seL4_MessageInfo_get_length(tag); i++) {
        seL4_SetMR(i, i);
    }
    last_spins = data->spins;
    last_bounces = data->bounces;
    seL4_Send(data->ep1, tag);
    /* We block, causing thread 2 to spin for a while, before it calls the
     * bouncer thread 0, which finally lets thread 1 run and reply to us. */
    CHECK_STEP(ipc_test_step, 2);
    CHECK_TESTCASE(result, data->spins - last_spins == 1);
    CHECK_TESTCASE(result, data->bounces - last_bounces == 0);

    /* Now bounce ourselves, to ensure that thread 1 can check its stuff. */
    seL4_MessageInfo_ptr_set_length(&tag, 0);
    seL4_Call(data->ep0, tag);

    /* Two bounces - us and thread 1. */
    CHECK_TESTCASE(result, data->spins - last_spins == 2);
    CHECK_TESTCASE(result, data->bounces - last_bounces == 2);
    CHECK_STEP(ipc_test_step, 4);

    /* TEST PART 2 */
    /* Perform a send to a thread 1, which is already waiting. */
    /* Bounce first to let thread prepare. */
    last_spins = data->spins;
    last_bounces = data->bounces;

    seL4_MessageInfo_ptr_set_length(&tag, 0);
    seL4_Call(data->ep0, tag);
    CHECK_STEP(ipc_test_step, 6);

    /* Do the send. */
    seL4_MessageInfo_ptr_set_length(&tag, 19);
    for (int i = 0; i < seL4_MessageInfo_get_length(tag); i++) {
        seL4_SetMR(i, i);
    }
    seL4_Send(data->ep1, tag);

    CHECK_STEP(ipc_test_step, 7);

    /* Bounce to let thread 1 check again. */
    seL4_MessageInfo_ptr_set_length(&tag, 0);
    seL4_Call(data->ep0, tag);

    CHECK_STEP(ipc_test_step, 9);

    /* Five bounces in total. */
    CHECK_TESTCASE(result, data->spins - last_spins == 2);
    CHECK_TESTCASE(result, data->bounces - last_bounces == 5);

    return result;
}