Пример #1
0
void test_load(void) {
    luaradio_t *radio;

    ptest();

    /* Create context */
    passert((radio = luaradio_new()) != NULL);

    /* Test invalid load: error in script */
    passert(luaradio_load(radio, "error('foobar')") < 0);
    passert(luaradio_start(radio) < 0);

    /* Test invalid load: no object returned */
    passert(luaradio_load(radio, "x = 5") < 0);
    passert(luaradio_start(radio) < 0);

    /* Test invalid load: not radio.CompositeBlock instance returned */
    passert(luaradio_load(radio, "return 5") < 0);
    passert(luaradio_start(radio) < 0);

    /* Test valid load: radio.CompositeBlock instance */
    passert(luaradio_load(radio, "return radio.CompositeBlock()") == 0);
    passert(luaradio_start(radio) == 0);

    luaradio_free(radio);
}
Пример #2
0
void test_flowgraph1(void) {
    luaradio_t *radio;
    int source_pipe[2];

    const char *script_template =
        "return radio.CompositeBlock():connect(\n"
            "radio.RawFileSource(%d, radio.types.Byte, 1),\n"
            "radio.DelayBlock(10),\n"
            "radio.PrintSink()\n"
        ")";
    char script[256];

    ptest();

    /* Create pipe */
    assert(pipe(source_pipe) == 0);

    /* Create context */
    passert((radio = luaradio_new()) != NULL);

    /* Prepare script */
    snprintf(script, sizeof(script), script_template, source_pipe[0]);

    /* Load script */
    passert(luaradio_load(radio, script) == 0);

    /* Start flow graph */
    passert(luaradio_start(radio) == 0);

    /* Close read end of pipe */
    passert(close(source_pipe[0]) == 0);

    /* Check flow graph status */
    bool running;
    passert(luaradio_status(radio, &running) == 0);
    passert(running == true);

    /* Break pipe */
    passert(close(source_pipe[1]) == 0);

    /* Check flow graph terminates naturally */
    time_t tic = time(NULL);
    while (true) {
        assert(luaradio_status(radio, &running) == 0);
        if (running == false)
            break;

        if ((time(NULL) - tic) > 5)
            passert(false);
    }

    /* Wait should return immediately */
    passert(luaradio_wait(radio) == 0);

    luaradio_free(radio);
}
Пример #3
0
void test_loopback(void) {
    serial_t serial;
    unsigned int count;
    time_t start, stop;
    uint8_t lorem_ipsum[] = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
    uint8_t lorem_hugesum[4096*3];
    uint8_t buf[sizeof(lorem_hugesum)];

    ptest();

    passert(serial_open(&serial, device, 115200) == 0);

    /* Test write/flush/read */
    passert(serial_write(&serial, lorem_ipsum, sizeof(lorem_ipsum)) == sizeof(lorem_ipsum));
    passert(serial_flush(&serial) == 0);
    passert(serial_read(&serial, buf, sizeof(lorem_ipsum), -1) == sizeof(lorem_ipsum));
    passert(memcmp(lorem_ipsum, buf, sizeof(lorem_ipsum)) == 0);

    /* Test poll/write/flush/poll/input waiting/read */
    passert(serial_poll(&serial, 500) == 0); /* Should timeout */
    passert(serial_write(&serial, lorem_ipsum, sizeof(lorem_ipsum)) == sizeof(lorem_ipsum));
    passert(serial_flush(&serial) == 0);
    passert(serial_poll(&serial, 500) == 1);
    usleep(500000);
    passert(serial_input_waiting(&serial, &count) == 0);
    passert(count == sizeof(lorem_ipsum));
    passert(serial_read(&serial, buf, sizeof(lorem_ipsum), -1) == sizeof(lorem_ipsum));
    passert(memcmp(lorem_ipsum, buf, sizeof(lorem_ipsum)) == 0);

    /* Test non-blocking poll */
    passert(serial_poll(&serial, 0) == 0);

    /* Test a very large read-write (likely to exceed internal buffer size (~4096)) */
    memset(lorem_hugesum, 0xAA, sizeof(lorem_hugesum));
    passert(serial_write(&serial, lorem_hugesum, sizeof(lorem_hugesum)) == sizeof(lorem_hugesum));
    passert(serial_flush(&serial) == 0);
    passert(serial_read(&serial, buf, sizeof(lorem_hugesum), -1) == sizeof(lorem_hugesum));
    passert(memcmp(lorem_hugesum, buf, sizeof(lorem_hugesum)) == 0);

    /* Test read timeout */
    start = time(NULL);
    passert(serial_read(&serial, buf, sizeof(buf), 2000) == 0);
    stop = time(NULL);
    passert((stop - start) > 1);

    /* Test non-blocking read */
    start = time(NULL);
    passert(serial_read(&serial, buf, sizeof(buf), 0) == 0);
    stop = time(NULL);
    /* Assuming we weren't context switched out for a second and weren't on a
     * thin time boundary ;) */
    passert((stop - start) == 0);

    passert(serial_close(&serial) == 0);
}
Пример #4
0
void test_open_config_close(void) {
    serial_t serial;
    uint32_t baudrate;
    unsigned int databits;
    serial_parity_t parity;
    unsigned int stopbits;
    bool xonxoff;
    bool rtscts;

    ptest();

    passert(serial_open(&serial, device, 115200) == 0);

    /* Check default settings */
    passert(serial_get_baudrate(&serial, &baudrate) == 0);
    passert(baudrate == 115200);
    passert(serial_get_databits(&serial, &databits) == 0);
    passert(databits == 8);
    passert(serial_get_parity(&serial, &parity) == 0);
    passert(parity == PARITY_NONE);
    passert(serial_get_stopbits(&serial, &stopbits) == 0);
    passert(stopbits == 1);
    passert(serial_get_xonxoff(&serial, &xonxoff) == 0);
    passert(xonxoff == false);
    passert(serial_get_rtscts(&serial, &rtscts) == 0);
    passert(rtscts == false);

    /* Change some stuff around */
    passert(serial_set_baudrate(&serial, 4800) == 0);
    passert(serial_get_baudrate(&serial, &baudrate) == 0);
    passert(baudrate == 4800);
    passert(serial_set_baudrate(&serial, 9600) == 0);
    passert(serial_get_baudrate(&serial, &baudrate) == 0);
    passert(baudrate == 9600);
    passert(serial_set_databits(&serial, 7) == 0);
    passert(serial_get_databits(&serial, &databits) == 0);
    passert(databits == 7);
    passert(serial_set_parity(&serial, PARITY_ODD) == 0);
    passert(serial_get_parity(&serial, &parity) == 0);
    passert(parity == PARITY_ODD);
    passert(serial_set_stopbits(&serial, 2) == 0);
    passert(serial_get_stopbits(&serial, &stopbits) == 0);
    passert(stopbits == 2);
    passert(serial_set_xonxoff(&serial, true) == 0);
    passert(serial_get_xonxoff(&serial, &xonxoff) == 0);
    passert(xonxoff == true);
    #if 0
    passert(serial_set_rtscts(&serial, true) == 0);
    passert(serial_get_rtscts(&serial, &rtscts) == 0);
    passert(rtscts == true);
    #endif
    /* Test serial port may not support rtscts */

    passert(serial_close(&serial) == 0);
}
Пример #5
0
void test_arguments(void) {
    serial_t serial;

    ptest();

    /* Invalid data bits (4 and 9) */
    passert(serial_open_advanced(&serial, device, 115200, 4, PARITY_NONE, 1, false, false) == SERIAL_ERROR_ARG);
    passert(serial_open_advanced(&serial, device, 115200, 9, PARITY_NONE, 1, false, false) == SERIAL_ERROR_ARG);
    /* Invalid parity */
    passert(serial_open_advanced(&serial, device, 115200, 8, PARITY_EVEN+1, 1, false, false) == SERIAL_ERROR_ARG);
    /* Invalid stopbits */
    passert(serial_open_advanced(&serial, device, 115200, 8, PARITY_NONE, 0, false, false) == SERIAL_ERROR_ARG);
    passert(serial_open_advanced(&serial, device, 115200, 8, PARITY_NONE, 3, false, false) == SERIAL_ERROR_ARG);

    /* Everything else is fair game, although termios might not like it. */
}
Пример #6
0
void test_context(void) {
    luaradio_t *radio;

    ptest();

    /* Create context */
    passert((radio = luaradio_new()) != NULL);

    /* Get Lua state */
    passert(luaradio_get_state(radio) != NULL);

    /* Flow graph operations should fail, since no composite block is loaded */
    passert(luaradio_start(radio) < 0);
    passert(luaradio_status(radio, NULL) < 0);
    passert(luaradio_wait(radio) < 0);
    passert(luaradio_stop(radio) < 0);

    luaradio_free(radio);
}
Пример #7
0
int main( int argc, char *argv[] ){
    if( argc < 2 ){
        printf("Expecting at least one argument. Please try again\n");
   	}
    else if(argc==2){
        if(atoi(argv[1])==1){
            p1();
        }
        else if(atoi(argv[1])==2){
            ptest();
        }
        else{
            printf("Incorrect argument supplied.\n");
        }
    }
    else
    {
        printf("Expecting only one argument\n");
    }
}
Пример #8
0
    /* This implementation only cares about beacons, so that's all we record */
    void Handle80211MgmtBeacon(const struct timeval& t, const mgmt_header_t *hdr, const mgmt_body_t *body) {
        if (opt_enforce_80211_frame_checksum && !fcs_ok) return;
#ifdef DEBUG_WIFI
        cout << "  " << "802.11 mgmt:\t" 
             << hdr->sa << "\tbeacon\t\"" << body->ssid.ssid << "\"" << endl;
#endif
        mac_ssid_pair ptest(&hdr->sa,body->ssid.ssid);

        //cout << "check " << hdr->sa << " to " << body->ssid.ssid << "\n";


        if(mac_ssids_seen.find(ptest)==mac_ssids_seen.end()){
            const MAC *m2 = new MAC(hdr->sa);
            const char *s2 = strdup(body->ssid.ssid);
            mac_ssid_pair pi(m2,s2);
            
            cout << "new mapping " << *ptest.first << "->" << ptest.second << "\n";
            mac_ssids_seen.insert(pi);
            /* TK3: How do we get this into the XML? */
        }
    }
Пример #9
0
void test_interactive(void) {
    serial_t serial;
    uint8_t buf[] = "Hello World";

    ptest();

    passert(serial_open(&serial, device, 4800) == 0);

    printf("Starting interactive test. Get out your logic analyzer, buddy!\n");
    printf("Press enter to continue...\n");
    getc(stdin);

    printf("Press enter to start transfer...");
    getc(stdin);
    passert(serial_write(&serial, buf, sizeof(buf)) == sizeof(buf));
    printf("Serial transfer baudrate 4800, 8n1 occurred? y/n\n");
    passert(getc_yes());

    passert(serial_set_baudrate(&serial, 9600) == 0);

    printf("Press enter to start transfer...");
    getc(stdin);
    passert(serial_write(&serial, buf, sizeof(buf)) == sizeof(buf));
    printf("Serial transfer baudrate 9600, 8n1 occurred? y/n\n");
    passert(getc_yes());

    passert(serial_set_baudrate(&serial, 115200) == 0);

    printf("Press enter to start transfer...");
    getc(stdin);
    passert(serial_write(&serial, buf, sizeof(buf)) == sizeof(buf));
    printf("Serial transfer baudrate 115200, 8n1 occurred? y/n\n");
    passert(getc_yes());

    passert(serial_close(&serial) == 0);
}
Пример #10
0
//-*****************************************************************************
int main( int argc, char *argv[] )
{
    bool opt_all = false;
    bool opt_meta = false;
    std::string desc( "abctree [OPTION] FILE[/NAME]\n"
    "  -a          include properties listings\n"
    "  -h, --help  prints this help message\n"
    "  -m          print metadata\n"
    );

    // check for min args
    if ( argc < 2 ) {
        std::cout << desc << std::endl;
        return 0;
    };

    // parse args
    std::vector<std::string> arguments(argv, argv + argc);
    std::vector<std::string> options;
    std::vector<std::string> files;

    // separate file args from option args 
    for ( std::size_t i = 1; i < arguments.size(); i++ ) {
        if ( arguments[ i ].substr( 0, 1 ) == "-" )
            options.push_back( arguments[ i ] );
        else
            files.push_back( arguments[ i ] );
    }

    // help
    if ( argc < 2 ||
         optionExists( options, "h" ) ||
         optionExists( options, "help" )
       ) {
        std::cout << desc << std::endl;
        return 0;
    };

    // set some flags
    opt_all = optionExists( options, "a");
    opt_meta = optionExists( options, "m");

    // open each file
    size_t count = 0;
    for ( std::size_t i = 0; i < files.size(); i++ ) {
        if ( files.size() > 1 )
            std::cout << BOLD << files[i] << ':' << RESETCOLOR << std::endl;

        std::stringstream ss( files[i] );
        std::stringstream fp;
        std::string segment;
        std::vector<std::string> seglist;

        /* 
         * separate file and object paths, e.g.
         *
         *   ../dir1/foo.abc/bar/baz
         *   \_____________/\______/
         *        file         obj
         */
        int j = 0;
        while ( std::getline( ss, segment, '/' ) ) {
            if ( !isFile ( fp.str() ) ) {
                if ( j != 0 )
                    fp << "/";
                fp << segment;
            } else {
                seglist.push_back( segment );
            }
            ++j;
        }

        // open the iarchive
        Abc::IArchive archive;
        AbcF::IFactory factory;
        factory.setPolicy(Abc::ErrorHandler::kQuietNoopPolicy);
        AbcF::IFactory::CoreType coreType;
        archive = factory.getArchive(std::string( fp.str() ), coreType);

        // display file metadata 
        if ( opt_meta ) {
            std::cout  << "Using "
                       << Alembic::AbcCoreAbstract::GetLibraryVersion ()
                       << std::endl;;

            std::string appName;
            std::string libraryVersionString;
            Alembic::Util::uint32_t libraryVersion;
            std::string whenWritten;
            std::string userDescription;
            std::string coreName;
            GetArchiveInfo (archive,
                            appName,
                            libraryVersionString,
                            libraryVersion,
                            whenWritten,
                            userDescription);

            if ( coreType == AbcF::IFactory::kOgawa ) {
                coreName = "Ogawa";
            } else if ( coreType == AbcF::IFactory::kHDF5 ) {
                coreName = "HDF5";
            } else {
                coreName = "Unknown";
            };

            if ( appName != "" ) {
                std::cout << "  file written by: " << appName << std::endl;
                std::cout << "  using Alembic : " << libraryVersionString << std::endl;
                std::cout << "  written on : " << whenWritten << std::endl;
                std::cout << "  user description : " << userDescription << std::endl;
            } else {
                std::cout << "  (file doesn't have any ArchiveInfo)"
                          << std::endl;
            }
            std::cout << "  core type : " << coreName << std::endl;
        };

        // walk object hierarchy and find valid objects
        AbcG::IObject test = archive.getTop();
        AbcG::IObject iObj = test;
        while ( test.valid() && seglist.size() > 0 ) {
            test = test.getChild( seglist.front() );
            if ( test.valid() ) {
                iObj = test;
                seglist.erase( seglist.begin() );
            }
        }

        // walk property hierarchy for most recent valid object
        Abc::ICompoundProperty props = iObj.getProperties();
        const Abc::PropertyHeader* header;
        bool found = false;
        for ( std::size_t i = 0; i < seglist.size(); ++i ) {
            header = props.getPropertyHeader( seglist[i] );
            if ( header && header->isCompound() ) {
                Abc::ICompoundProperty ptest( props, header->getName() );
                if ( ptest.valid() ) {
                    props = ptest;
                    found = true;
                }
            } else if ( header && header->isSimple() ) {
                found = true;
            } else {
                std::cout << seglist[i] 
                          << ": Invalid object or property" 
                          << std::endl;
                return 1;
            }
        }

        // walk the archive tree
        if ( found ) 
            if ( header->isCompound() )
                tree( props );
            else
                tree( Abc::IScalarProperty( props, header->getName() ) );
        else
            tree( iObj, opt_all );

        ++count;
    }

    return 0;
}
Пример #11
0
void test_spi_flash(void) {
    struct spi_slave spi;
    struct spi_flash flash;
    unsigned int addr, i;
    int ret;

    /* We use a 512 byte buf for verifications below because of limited RAM */
    uint8_t buf[512];

    ptest();

    /* Enable PIO0.2 for CS */
    LPC_GPIO0->DIR |= (1<<2);

    /* Configure SPI */
    spi.master = &SPI0;
    spi.speed = 24000000;
    spi.mode = 0;
    spi.cs_pin = 2;
    spi.cs_active_high = false;

    debug_printf(STR_TAB "Press enter to start SPI flash test...\n");
    uart_getc(); uart_putc('\n');

    /* Probe for the flash */
    debug_printf(STR_TAB "Probing for SPI flash chip...\n");
    passert(spi_flash_probe(&flash, &spi) == 0);
    pokay("Found SPI flash!");
    pokay("  JEDEC ID: 0x%08x", flash.params->jedec_id);
    pokay("  Name: %s", flash.params->name);
    pokay("  Sector Size: %d", flash.params->sector_size);
    pokay("  Capacity: %d", flash.params->capacity);
    pokay("  Flags: %04x", flash.params->flags);

    debug_printf(STR_TAB "Testing invalid argument checks of SPI flash functions\n");
    /* Make sure not sector size mod address and length fail */
    passert(spi_flash_erase(&flash, 0x5, 4096) == SPI_FLASH_ERROR_ARGS);
    passert(spi_flash_erase(&flash, 0, 4095) == SPI_FLASH_ERROR_ARGS);
    /* Make sure program out of bounds fails */
    passert(spi_flash_write(&flash, 0x3, NULL, flash.params->capacity) == SPI_FLASH_ERROR_ARGS);

    /* Erase two sectors */
    debug_printf(STR_TAB "Erasing lower two sectors...\n");
    passert(spi_flash_erase(&flash, 0x0, 4096*2) == 0);

    /* Verify they are all 0xff */
    debug_printf(STR_TAB "Verifying lower two sectors are blank...\n");
    for (addr = 0; addr < 4096*2; addr += sizeof(buf)) {
        if ((ret = spi_flash_read(&flash, addr, buf, sizeof(buf))) != 0) {
            pfail("Error with spi_flash_read(): %d", ret);
            passert(false);
        }
        for (i = 0; i < sizeof(buf); i++) {
            if (buf[i] != 0xff) {
                pfail("Memory is not blank at address 0x%06x! got 0x%02x", addr+i, buf[i]);
                passert(false);
            }
        }
    }
    pokay("Lower two sectors are blank");

    debug_printf(STR_TAB "Starting write/read/verify test vector tests...\n");

    /* Write test vector 1 to 0x003 - 0x04e inclusive (75 bytes) */
    passert(spi_flash_write(&flash, 0x03, test_sf_vector1, sizeof(test_sf_vector1)) == 0);
    pokay("Wrote test vector 1 to 0x003-0x04e");
    /* Verify test vector 1 data from 0x000 - 0x0ff */
    passert(spi_flash_read(&flash, 0x0, buf, sizeof(buf)) == 0);
    passert(memcmp(buf, test_sf_vector_blank, 3) == 0);
    passert(memcmp(buf+3, test_sf_vector1, sizeof(test_sf_vector1)) == 0);
    passert(memcmp(buf+3+sizeof(test_sf_vector1), test_sf_vector_blank, 0x100-3-sizeof(test_sf_vector1)) == 0);
    pokay("Read test vector 1 verified 0x000-0x0ff");

    /* Write test vector 2 to 0x100 - 0x1ff inclusive (1 page == 256 bytes) */
    passert(spi_flash_write(&flash, 0x100, test_sf_vector2, sizeof(test_sf_vector2)) == 0);
    pokay("Wrote test vector 2 to 0x100-0x1ff");
    /* Verify test vector 1 again */
    debug_printf(STR_TAB "Verifying test vector 1 again\n");
    passert(spi_flash_read(&flash, 0x0, buf, sizeof(buf)) == 0);
    passert(memcmp(buf, test_sf_vector_blank, 3) == 0);
    passert(memcmp(buf+3, test_sf_vector1, sizeof(test_sf_vector1)) == 0);
    passert(memcmp(buf+3+sizeof(test_sf_vector1), test_sf_vector_blank, 0x100-3-sizeof(test_sf_vector1)) == 0);
    pokay("Read test vector 1 verified 0x000-0x0ff");
    /* Verify test vector 2 */
    passert(spi_flash_read(&flash, 0x100, buf, sizeof(buf)) == 0);
    passert(memcmp(buf, test_sf_vector2, sizeof(test_sf_vector2)) == 0);
    pokay("Read test vector 2 verified 0x100-0x1ff");

    /* Write test vector 3 to 0x200 - 0x301 inclusive (1 page, 1 byte == 257 bytes) */
    passert(spi_flash_write(&flash, 0x200, test_sf_vector3, sizeof(test_sf_vector3)) == 0);
    pokay("Wrote test vector 3 to 0x200-0x301");
    /* Verify test vector 3 */
    passert(spi_flash_read(&flash, 0x200, buf, sizeof(buf)) == 0);
    passert(memcmp(buf, test_sf_vector3, sizeof(test_sf_vector3)) == 0);
    passert(memcmp(buf+sizeof(test_sf_vector3), test_sf_vector_blank, 0x100-1) == 0);
    pokay("Read test vector 3 verified 0x200-0x3ff");

    /* Write test vector 4 to 0x37f - 0x5ff inclusive (2.5 pages == 640 bytes) */
    passert(spi_flash_write(&flash, 0x37f, test_sf_vector4, sizeof(test_sf_vector4)) == 0);
    pokay("Wrote test vector 4 to 0x37f-0x5ff");
    /* Verify test vector 4 */
    /* First 512 bytes */
    passert(spi_flash_read(&flash, 0x37f, buf, sizeof(buf)) == 0);
    passert(memcmp(buf, test_sf_vector4, 512) == 0);
    /* Last 128 bytes (and 384 blank bytes) */
    passert(spi_flash_read(&flash, 0x37f+512, buf, sizeof(buf)) == 0);
    passert(memcmp(buf, test_sf_vector4+512, 128) == 0);
    passert(memcmp(buf+128, test_sf_vector_blank, 384) == 0);
    pokay("Read test vector 4 verified 0x37f-0x5ff");

    debug_printf(STR_TAB "Erasing entire chip... Press enter to continue.");
    uart_getc(); uart_putc('\n');

    /* Erase chip */
    passert(spi_flash_erase(&flash, 0x0, flash.params->capacity) == 0);
    /* Verify lower 256kB is blank */
    debug_printf(STR_TAB "Verifying lower 256kB is blank...\n");
    for (addr = 0; addr < 256*1024; addr += sizeof(buf)) {
        if ((ret = spi_flash_read(&flash, addr, buf, sizeof(buf))) != 0) {
            pfail("Error with spi_flash_read(): %d", ret);
            passert(false);
        }
        for (i = 0; i < sizeof(buf); i++) {
            if (buf[i] != 0xff) {
                pfail("Memory is not blank at address 0x%06x! got 0x%02x", addr+i, buf[i]);
                passert(false);
            }
        }
    }
    pokay("Lower 256kB is blank");

    debug_printf(STR_TAB "Starting pseudorandom data test... Press enter to continue.");
    uart_getc(); uart_putc('\n');

    /* Write 256kB pseudorandom data */
    debug_printf(STR_TAB "Writing 256kB pseudorandom data\n");
    srand(0xdeadbeef);
    for (addr = 0; addr < 256*1024; addr += sizeof(buf)) {
        for (i = 0; i < sizeof(buf); i++)
            buf[i] = rand();
        if (spi_flash_write(&flash, addr, buf, sizeof(buf)) != 0) {
            pfail("Error with spi_flash_write(): %d", ret);
            passert(false);
        }
    }
    pokay("Wrote 256kB pseudorandom data");
    /* Verify 256kB pseudorandom data */
    debug_printf(STR_TAB "Verifying 256kB pseudorandom data\n");
    srand(0xdeadbeef);
    for (addr = 0; addr < 256*1024; addr += sizeof(buf)) {
        if ((ret = spi_flash_read(&flash, addr, buf, sizeof(buf))) != 0) {
            pfail("Error with spi_flash_read(): %d", ret);
            passert(false);
        }
        for (i = 0; i < sizeof(buf); i++) {
            uint8_t x = rand();
            if (buf[i] != x) {
                pfail("Pseudorandom data mismatch at address 0x%06x! expected 0x%02x, got 0x%02x", addr+i, x, buf[i]);
                passert(false);
            }
        }
    }
    pokay("Pseudorandom data matches!");
}
Пример #12
0
void test_mcp23008(void) {
    struct mcp23008 mcp;
    int state;

    ptest();

    debug_printf(STR_TAB "Press enter to start MCP23008 test...");
    uart_getc(); uart_putc('\n');

    /* Probe for the I/O expander */
    debug_printf(STR_TAB "Probing for MCP23008...\n");
    passert(mcp23008_probe(&mcp, &I2C0, 0x20) == 0);
    pokay("Found MCP23008!");

    debug_printf(STR_TAB "Initializing P4-P7 to outputs with value 1\n");
    passert(mcp23008_reg_write(&mcp, MCP_REG_OLAT, 0xf0) == 0);
    passert(mcp23008_reg_write(&mcp, MCP_REG_IODIR, 0x0f) == 0);
    passert(mcp23008_reg_write(&mcp, MCP_REG_IPOL, 0x00) == 0);

    debug_printf(STR_TAB "Press enter to turn on LED1...");
    uart_getc(); uart_putc('\n');
    passert(mcp23008_reg_write(&mcp, MCP_REG_GPIO, ~(1<<4) & 0xf0) == 0);
    do { pinteract("LED1 on?"); } while(0);

    debug_printf(STR_TAB "Press enter to turn on LED2...");
    uart_getc(); uart_putc('\n');
    passert(mcp23008_reg_write(&mcp, MCP_REG_GPIO, ~(1<<5) & 0xf0) == 0);
    do { pinteract("LED2 on?"); } while(0);

    debug_printf(STR_TAB "Press enter to turn on LED3...");
    uart_getc(); uart_putc('\n');
    passert(mcp23008_reg_write(&mcp, MCP_REG_GPIO, ~(1<<6) & 0xf0) == 0);
    do { pinteract("LED3 on?"); } while(0);

    debug_printf(STR_TAB "Press enter to turn on LED4...");
    uart_getc(); uart_putc('\n');
    passert(mcp23008_reg_write(&mcp, MCP_REG_GPIO, ~(1<<7) & 0xf0) == 0);
    do { pinteract("LED4 on?"); } while(0);

    debug_printf(STR_TAB "Press enter to turn on all LEDs...");
    uart_getc(); uart_putc('\n');
    passert(mcp23008_reg_write(&mcp, MCP_REG_GPIO, 0x00) == 0);
    do { pinteract("All LEDs on?"); } while(0);

    debug_printf(STR_TAB "Polling GPIOs\n");
    state = 0;
    while (1) {
        uint8_t data;

        if (state == 0) {
            debug_printf(STR_TAB "Waiting for button 1 press...\n");
            state++;
        } else if (state == 2) {
            debug_printf(STR_TAB "Waiting for button 2 press...\n");
            state++;
        } else if (state == 4) {
            debug_printf(STR_TAB "Waiting for switch 1 on...\n");
            state++;
        } else if (state == 6) {
            debug_printf(STR_TAB "Waiting for switch 2 on...\n");
            state++;
        } else if (state == 8) {
            break;
        }

        if (mcp23008_reg_read(&mcp, MCP_REG_GPIO, &data) < 0) {
            pfail("mcp23008_reg_read() failed");
            passert(false);
        }

        if (state == 1 && !(data & (1<<2))) {
            pokay("Got button 1 press!");
            state++;
        } else if (state == 3 && !(data & (1<<3))) {
            pokay("Got button 2 press!");
            state++;
        } else if (state == 5 && !(data & (1<<0))) {
            pokay("Got switch 1 on!");
            state++;
        } else if (state == 7 && !(data & (1<<1))) {
            pokay("Got switch 2 on!");
            state++;
        }

        delay_ms(25);
    }
}
Пример #13
0
int main()
{
 void *data;
 char *command1, *command2, *def;
 int result;
 FILE *fp = fopen("hashlog.txt", "w");
 CHTbl *htbl = malloc(sizeof(CHTbl));
 chtbl_init(htbl, 4, g3, vstrcmp, NULL);
 fprintf(fp, "Load factor\tOccupancy\n", (float)(htbl->size/htbl->buckets), htbl->buckets);
 while(1)
 {
  printf(">");
  command1 = malloc(sizeof(char)*10);
  command2 = malloc(sizeof(char)*50);
  def = malloc(sizeof(char)*1000);
  result = (parseline(command1, command2, def));


  switch(result){
   case -1:
    printf("Error: invalid use of 'add'\n");
    free(command2);
    free(def);
    break;
   case -2:
    printf("Error: invalid use of 'delete'\n");
    free(command2);
    free(def);
    break;
   case -3:
    printf("Error: invalid use of 'find'\n");
    free(command2);
    free(def);
    break;
   case -4:
    printf("Error: command not recognized\n");
    free(command2);
    free(def);
    break;
   case -5:
    printf("Error: no filename given");
    free(command2);
    free(def);
   case 1:
    if(!(chtbl_insert(&htbl, command2, def)))
    {
     printf("Added %s to dictionary\n", command2);
     printtolog(fp, htbl);
    }
    else printf("Error - %s not added to dictionary\n", command2);
    break;
   case 2:
    free(def);
    if(!htbl_remove(htbl, command2))
    {
     printf("Deleted %s from dictionary\n", command2);
     printtolog(fp, htbl);
    }
    else printf("Error - %s not found\n", command2);
    free(command2);
    break;
   case 3:
    free(def);
    if(!chtbl_lookup(htbl, command2, &data))
    {
     printf("%s\n", command2);
     printf("%s\n", (char *)data);
    }
    else printf("%s not found in dictionary\n", command2);
    free(command2);
    break;
   case 4:
    free(command2);
    free(def);
    print_table(htbl);
    break;
   case 5:
    free(command1);
    free(command2);
    free(def);
    destroy_table(htbl);
    free(htbl);
    fclose(fp);
    return 0;
    break; 
   case 6:
    if(!readfile(htbl, command2, fp))
     printf("File scanned to dictionary\n");
    else printf("Error - file not scanned\n");
    free(command2);
    break;
   case 7:
    find2(htbl, command2, def);
    free(command2);
    free(def);
    break;
   case 8:
    ptest(htbl, command2, fp);
    break;
   }
 
 free(command1);
 }
}
Пример #14
0
//===============================================
//     Unit Tests
//===============================================
int main() {
    // set for command line argument -t to run unit tests.
    bool test = true;

    if (test) {
        std::cout<<"\n=================\nBegin UNIT TESTS\n=================\n\n";
        Light::Light n = *new Light::Light(0, 1, 1, 0, 0.5, 0.5, 0.5);
        n.print();

        Intersect::Intersect i = *new Intersect::Intersect();
        if(i.isHit()) {
            std::cout<<"INCORRECT! hit is true.\n\n";
        }
        else {
            std::cout<<"CORRECT! hit is false.\n\n";
            i.setHit(true);
        }
        if(i.isHit()) {
            std::cout<<"CORRECT! hit is true.\n\n";
        }
        else {
            std::cout<<"INCORRECT! hit is false.\n\n";
        }
        std::vector<float> ptest(3);
        ptest[0] = 0;
        ptest[1] = 1;
        ptest[2] = 2;
        i.setPoint(ptest);
        std::vector<float> p = i.getPoint();
        std::cout<< "[" << p[0] << ", " << p[1] << ", " << p[2] << "]\n";

        Vertex::Vertex a = *new Vertex::Vertex(0,0,0);
        Vertex::Vertex b = *new Vertex::Vertex(1,0,0);
        Vertex::Vertex c = *new Vertex::Vertex(0,1,0);
        a.print();
        a = a.sub(b);
        a.print();
        std::vector<float> d = c.toVec();
        std::cout<<"vec ["<< d[0] << ", " << d[1] << ", " << d[2] << "]\n";
        Vertex::Vertex e1 = *new Vertex::Vertex(d);
        e1.print();
        Vertex a1 = *new Vertex::Vertex(0,1,0);
        Vertex b1 = *new Vertex::Vertex(1,-1,0);
        Vertex c1 = *new Vertex::Vertex(-1,-1,0);
        Triangle t = *new Triangle::Triangle(a1,b1,c1);
        p[0] = 0;
        p[1] = 0;
        p[2] = 0;
        std::vector<float> e(3);
        e[0] = 0;
        e[1] = 0;
        e[2] = 3;

        Ray::Ray r = *new Ray::Ray(e, p);
        i = t.intersect(r);
        if (i.isHit()) {
            std::cout<<"Triangle Intersected - OKAY\n";
        }
        Sphere::Sphere s = *new Sphere::Sphere(1, p);
        if (s.intersect(r).isHit()) {
            std::cout<<"Sphere Intersected - OKAY\n";
        }


        e[0] = 0;
        e[1] = -4;
        e[2] = -4;
        p[0] = 1;
        p[1] = 1;
        p[2] = -1;
        r.setEye(e);
        r.setPoint(p);
        std::cout<<"projected ";
        vPrint(r.project(1.5));


        PPM* ppm = new PPM(640, 480, 255);
        int val;
        for (float h = 0; h<480; h++) {
            for (float w =0; w<640; w++) {
                val = h;//std::min(255, (int)((w/639)*255.0f));
                ppm->addPixel(*(new Pixel::Pixel(val, val, val)));
            }
        }
        ppm->save("output");
        /*
        for (float h = 0; h < 3; h++) {
        	for (float w = 0; w< ppm->getW(); w++) {
        		std::cout<<w<<" ";
        		ppm->getPixel(w, h).print();
        	}
        }
        */

        std::cout<<"End PPM tests\n";
        Pixel::Pixel px = *new Pixel::Pixel(255, 255, 255);
        Pixel::Pixel black = *new Pixel::Pixel(0,0,0);
        Pixel::Pixel pfloat = *new Pixel::Pixel(1.0f, 0.9f, 0.05f);
        Pixel::Pixel pmax = *new Pixel::Pixel(2.0f, 1.0f, 0.5f);
        px.print();
        black.print();
        black.add(px);
        black.print();
        pfloat.print();
        pmax.print();


        std::vector<float> test1(3);
        test1[0] = 1;
        test1[1] = 0;
        test1[2] = 0.5;
        std::vector<float> test2(3);
        test2[0] = 0;
        test2[1] = 1;
        test2[2] = 0.5;
        std::cout<<vDot(test1, test2)<<"\n";
        vPrint(vSub(test1, test2));
        vPrint(vAdd(test1, test2));
        vPrint(vMult(test1, test2));
        vPrint(normalize(test1));
        vPrint(normalize(test2));
        vPrint(vCross(test1, test2));
        vPrint(vScale(-1, test1));

        std::cout<<"\n=================\nEnd UNIT TESTS\n=================\n\n";

        return 0;
    }
    else {
        return 0;
    }
}
Пример #15
0
void test_spi(void) {
    struct spi_slave spi;
    uint8_t txbuf[1024], rxbuf[1024];
    unsigned int i;

    ptest();

    /* Enable GPIO12 / PIO1.0 for CS */
    LPC_IOCON->R_PIO1_0 = 0x1;
    LPC_GPIO1->DIR |= (1<<0);

    /* Setup SPI slave */
    spi.master = &SPI0;
    spi.cs_pin = 12;
    spi.cs_active_high = false;
    spi.speed = 1000000;

    spi.mode = 0;
    _test_spi_transfer(&spi, "SPI mode=0, speed=1e6, cs active low");

    spi.mode = 1;
    _test_spi_transfer(&spi, "SPI mode=1, speed=1e6, cs active low");

    spi.mode = 2;
    _test_spi_transfer(&spi, "SPI mode=2, speed=1e6, cs active low");

    spi.mode = 3;
    _test_spi_transfer(&spi, "SPI mode=3, speed=1e6, cs active low");

    spi.mode = 0;
    spi.cs_active_high = true;
    _test_spi_transfer(&spi, "SPI mode=0, speed=1e6, cs active high");

    spi.mode = 0;
    spi.cs_active_high = false;
    spi.speed = 6000000;
    _test_spi_transfer(&spi, "SPI mode=0, speed=6e6, cs active low");

    spi.speed = 12000000;
    _test_spi_transfer(&spi, "SPI mode=0, speed=12e6, cs active low");

    spi.speed = 24000000;
    _test_spi_transfer(&spi, "SPI mode=0, speed=24e6, cs active low");

    debug_printf("\n");
    debug_printf(STR_TAB "Generating pseudorandom txbuf:\n");
    srand(0xdeadbeef);
    for (i = 0; i < sizeof(txbuf); i++) {
        txbuf[i] = (uint8_t)rand();
        rxbuf[i] = 0xff;
        debug_printf("%02x ", txbuf[i]);
    }
    debug_printf("\n");

    spi.speed = 1000000;
    debug_printf(STR_TAB "Please tie MISO and MOSI for loopback test and press enter...");
    uart_getc();
    uart_putc('\n');

    spi_setup(&spi);
    spi_select(&spi);
    spi_transfer(&spi, txbuf, rxbuf, sizeof(txbuf));
    spi_deselect(&spi);

    if (memcmp(txbuf, rxbuf, sizeof(txbuf)) == 0)
        pokay("SPI mode=0, speed=1e6 loopback success!");
    else {
        pfail("SPI mode=0, speed=1e6 loopback failed! Got back:");
        for (i = 0; i < sizeof(rxbuf); i++)
            debug_printf("%02x ", rxbuf[i]);
        debug_printf("\n");
    }
}
Пример #16
0
int main()
{
    void *data;
    char *command1, *command2, *def;
    int result;
    FILE *fp = fopen("treelog.txt", "w");
    RBtree *tree = malloc(sizeof(RBtree));
    init_tree(tree, vstrcmp, node_destroy, node_print);
    fprintf(fp, "Tree Height\n");
    while(1)
    {
        printf(">");
        command1 = malloc(sizeof(char)*10);
        command2 = malloc(sizeof(char)*50);
        def = malloc(sizeof(char)*1000);
        result = (parseline(command1, command2, def));


        switch(result) {
        case -1:
            printf("Error: invalid use of 'add'\n");
            free(command2);
            free(def);
            break;
        case -2:
            printf("Error: invalid use of 'delete'\n");
            free(command2);
            free(def);
            break;
        case -3:
            printf("Error: invalid use of 'find'\n");
            free(command2);
            free(def);
            break;
        case -4:
            printf("Error: command not recognized\n");
            free(command2);
            free(def);
            break;
        case -5:
            printf("Error: no filename given");
            free(command2);
            free(def);
        case 1:
            if(!insert_node(tree, command2, def))
            {
                printf("Added %s to dictionary\n", command2);
                printtolog(fp, tree);
            }
            else printf("Error - %s not added to dictionary\n", command2);
            break;
        case 2:
            free(def);
            if(!delete_node(tree, command2))
            {
                printf("Deleted %s from dictionary\n", command2);
                printtolog(fp, tree);
            }
            else printf("Error - %s not found\n", command2);
            free(command2);
            break;
        case 3:
            free(def);
            if(!find_node(tree, command2, &data))
            {
                printf("%s\n", command2);
                printf("%s\n", (char *)data);
            }
            else printf("%s not found in dictionary\n", command2);
            free(command2);
            break;
        case 4:
            free(command2);
            free(def);
            print_tree(tree, tree->root);
            break;
        case 5:
            free(command1);
            free(command2);
            free(def);
            destroy_tree(tree, tree->root);
            free(tree);
            fclose(fp);
            return 0;
            break;
        case 6:
            if(!readfile(tree, command2, fp))
                printf("File scanned to dictionary\n");
            else printf("Error - file not scanned\n");
            free(command2);
            break;
        case 7:
            find2(tree, tree->root, command2, def);
            free(command2);
            free(def);
            break;
        case 8:
            ptest(tree, command2, fp);
            free(command2);
            break;
        }

        free(command1);
    }
}
Пример #17
0
void test_flowgraph2(void) {
    luaradio_t *radio;
    bit_t source_buf[256], sink_buf[256];
    int source_pipe[2], sink_pipe[2];

    const char *script_template =
        "return radio.CompositeBlock():connect(\n"
            "radio.RawFileSource(%d, radio.types.Bit, 1),\n"
            "radio.DifferentialDecoderBlock(),\n"
            "radio.RawFileSink(%d)\n"
        ")";
    char script[256];

    ptest();

    /* Load source_buf with random bits */
    for (int i = 0; i < 256; i++) {
        source_buf[i].value = random() & 0x1;
    }

    /* Create source and sink pipes */
    passert(pipe(source_pipe) == 0);
    passert(pipe(sink_pipe) == 0);

    /* Load source buf into source pipe */
    passert(write(source_pipe[1], source_buf, sizeof(source_buf)) == sizeof(source_buf));
    passert(close(source_pipe[1]) == 0);

    /* Create context */
    passert((radio = luaradio_new()) != NULL);

    /* Prepare script */
    snprintf(script, sizeof(script), script_template, source_pipe[0], sink_pipe[1]);

    /* Load the script */
    passert(luaradio_load(radio, script) == 0);

    /* Start flow graph */
    passert(luaradio_start(radio) == 0);

    /* Close write end of sink pipe */
    passert(close(sink_pipe[1]) == 0);

    /* Wait for flow graph termination */
    passert(luaradio_wait(radio) == 0);

    /* Check script status */
    bool running;
    passert(luaradio_status(radio, &running) == 0);
    passert(running == false);

    /* Read sink pipe into sink buf */
    passert(read(sink_pipe[0], sink_buf, sizeof(sink_buf)) == sizeof(sink_buf));

    /* Close read ends of pipes */
    passert(close(source_pipe[0]) == 0);
    passert(close(sink_pipe[0]) == 0);

    /* Check sink buffer */
    for (int i = 0; i < 256; i++) {
        assert(sink_buf[i].value == (source_buf[i].value ^ ((i == 0) ? 0 : (source_buf[i-1].value))));
    }

    luaradio_free(radio);
}