//---------------------------------------------------------------------------------- u8 s_read_byte(u8 ack) //---------------------------------------------------------------------------------- // reads a byte form the Sensibus and gives an acknowledge in case of "ack=1" { u8 i,val=0; MAKE_I2CDATA_INPUT(); SETDATA(); //release DATA-line asm("nop");asm("nop"); for (i=0x80;i>0;i/=2) //shift bit for masking { SETSCK(); //clk for SENSI-BUS asm("nop");asm("nop"); if (READDATA()) val=(val | i); //read bit CLRSCK(); asm("nop");asm("nop"); } MAKE_I2CDATA_OUTPUT(); if(ack) CLRDATA(); else SETDATA(); //in case of "ack==1" pull down DATA-Line SETSCK(); //clk #9 for ack asm("nop");asm("nop"); //pulswith approx. 250 ns CLRSCK(); asm("nop");asm("nop"); SETDATA(); //release DATA-line return val; }
/* * stress_bsearch() * stress bsearch */ int stress_bsearch( uint64_t *const counter, const uint32_t instance, const uint64_t max_ops, const char *name) { int32_t *data, *ptr, prev = 0; size_t n, n8, i; (void)instance; if (!set_bsearch_size) { if (opt_flags & OPT_FLAGS_MAXIMIZE) opt_bsearch_size = MAX_BSEARCH_SIZE; if (opt_flags & OPT_FLAGS_MINIMIZE) opt_bsearch_size = MIN_BSEARCH_SIZE; } n = (size_t)opt_bsearch_size; n8 = (n + 7) & ~7; /* allocate in multiples of 8 */ if ((data = malloc(sizeof(int32_t) * n8)) == NULL) { pr_failed_dbg(name, "malloc"); return EXIT_FAILURE; } /* Populate with ascending data */ prev = 0; for (i = 0; i < n;) { uint64_t v = mwc64(); SETDATA(data, i, v, prev); SETDATA(data, i, v, prev); SETDATA(data, i, v, prev); SETDATA(data, i, v, prev); SETDATA(data, i, v, prev); SETDATA(data, i, v, prev); SETDATA(data, i, v, prev); SETDATA(data, i, v, prev); } do { for (ptr = data, i = 0; i < n; i++, ptr++) { int32_t *result; result = bsearch(ptr, data, n, sizeof(*ptr), cmp); if (opt_flags & OPT_FLAGS_VERIFY) { if (result == NULL) pr_fail(stderr, "%s: element %zu could not be found\n", name, i); else if (*result != *ptr) pr_fail(stderr, "%s: element %zu found %" PRIu32 ", expecting %" PRIu32 "\n", name, i, *result, *ptr); } } (*counter)++; } while (opt_do_run && (!max_ops || *counter < max_ops)); free(data); return EXIT_SUCCESS; }
//---------------------------------------------------------------------------------- void s_transstart(void) //---------------------------------------------------------------------------------- // generates a transmission start // _____ ________ // DATA: |_______| // ___ ___ // SCK : ___| |___| |______ { SETDATA(); CLRSCK(); //Initial state asm("nop");asm("nop"); SETSCK(); asm("nop");asm("nop"); CLRDATA(); asm("nop");asm("nop"); CLRSCK(); asm("nop");asm("nop"); SETSCK(); asm("nop");asm("nop"); SETDATA(); asm("nop");asm("nop"); CLRSCK(); }
//---------------------------------------------------------------------------------- u8 s_write_byte(u8 value) //---------------------------------------------------------------------------------- // writes a byte on the Sensibus and checks the acknowledge { u8 i,error=0; MAKE_I2CDATA_OUTPUT(); for (i=0x80;i>0;i/=2) //shift bit for masking { if (i & value) SETDATA(); //masking value with i , write to SENSI-BUS else CLRDATA(); SETSCK(); //clk for SENSI-BUS asm("nop");asm("nop"); //pulswith approx. 250 ns CLRSCK(); } SETDATA(); //release DATA-line MAKE_I2CDATA_INPUT(); asm("nop");asm("nop"); SETSCK(); //clk #9 for ack error=READDATA(); //check ack (DATA will be pulled down by SHT11) CLRSCK(); MAKE_I2CDATA_OUTPUT(); return error; //error=1 in case of no acknowledge }
//---------------------------------------------------------------------------------- void s_connectionreset(void) //---------------------------------------------------------------------------------- // communication reset: DATA-line=1 and at least 9 SCK cycles followed by transstart // _____________________________________________________ ________ // DATA: |_______| // _ _ _ _ _ _ _ _ _ ___ ___ // SCK : __| |__| |__| |__| |__| |__| |__| |__| |__| |______| |___| |______ { u8 i; SETDATA(); CLRSCK(); //Initial state for(i=0;i<9;i++) //9 SCK cycles { SETSCK(); CLRSCK(); } s_transstart(); //transmission start }
int main(){ char * stringToReturn; struct http_request request; int status; /* Set Shared Campaign_id */ _shared_campaign_id =1 ; stringToReturn = malloc(1000); request.method = POST; char * valid = "{ \"message\" : \"Test Debug\",\"stackTrace\" : \"stack trace\",\"origin\" : \"6f3d78c8ca1cca4f362c697d9\"}"; char * withType = "{ \"message\" : \"Test Debug\",\"stackTrace\" : \"stack trace\",\"origin\" : \"6f3d78c8ca1cca4f362c697d9\",\"type\":\"WARN\"}"; char * malformed = "{ { {{} }aaa}"; char * missingKeys = "{\"message\" : \"ms\"}"; char * emptyMsg = "{ \"message\" : \"\",\"stackTrace\" : \"stack trace\",\"origin\" : \"6f3d78c8ca1cca4f362c697d9\"}"; char * emptyTrace = "{ \"message\" : \"Test Debug\",\"stackTrace\" : \"\",\"origin\" : \"6f3d78c8ca1cca4f362c697d9\"}"; char * emptyOrigin = "{ \"message\" : \"Test Debug\",\"stackTrace\" : \"stack trace\",\"origin\" : \"\"}"; char * invalidType = "{ \"message\" : \"Test Debug\",\"stackTrace\" : \"stack trace\",\"origin\" : \"6f3d78c8ca1cca4f362c697d9\",\"type\":\"WAsRN\"}"; /* Valids */ sprintf(request.url, "/api/debug"); SETDATA(valid) status = report_controller(&request, &stringToReturn, 1000); EXPECTED(200, status, "Expected successful request") SETDATA(withType) status = report_controller(&request, &stringToReturn, 1000); EXPECTED(200, status, "Expected successful request") /* Invalids */ sprintf(request.url, "/api/debug"); SETDATA(malformed) status = report_controller(&request, &stringToReturn, 1000); EXPECTED(400, status, "Expected failed request") sprintf(request.url, "/api/debug"); SETDATA(missingKeys) status = report_controller(&request, &stringToReturn, 1000); EXPECTED(422, status, "Should have failed when missing keys from JSON") sprintf(request.url, "/api/debug"); SETDATA(emptyMsg) status = report_controller(&request, &stringToReturn, 1000); EXPECTED(422, status, "Should have failed with empty message") sprintf(request.url, "/api/debug"); SETDATA(emptyTrace) status = report_controller(&request, &stringToReturn, 1000); EXPECTED(422, status, "Should have failed with empty trace") sprintf(request.url, "/api/debug"); SETDATA(emptyOrigin) status = report_controller(&request, &stringToReturn, 1000); EXPECTED(422, status, "Should have failed when origin empty") SETDATA(invalidType) status = report_controller(&request, &stringToReturn, 1000); EXPECTED(400, status, "Expected failed request") free(stringToReturn); fflush(stdout); fflush(stderr); close(STDIN_FILENO); close(STDOUT_FILENO); close(STDERR_FILENO); return 0; }
LOGICAL irepnfree(addr thi, tail * at, cvalue c) /* thi and at are dummy arguments */ { movb; SETDATA(b,c); return(TRUE); }