/* * Return `true' p% of the time. */ bool DefaultRndNumGenerator::rnd_flipcoin(const unsigned int p, const Filter *f, const std::string *) { assert(p <= 100); unsigned INT64 local_depth = rand_depth_; rand_depth_++; if (f) { if (f->filter(0)) { add_number(1, 2, local_depth); return true; } else if (f->filter(1)) { add_number(0, 2, local_depth); return false; } } bool rv = (genrand() % 100) < p; if (rv) { add_number(1, 2, local_depth); } else { add_number(0, 2, local_depth); } return rv; }
sort_data* load_sort_data(char* datafilename) { sort_data* sd = NULL; FILE* fd = NULL; char buff[BUFF_SIZE]; char nbuf[BUFF_SIZE]; int number; int rl = 0; int ri = 0; int bi = 0; if (datafilename == NULL) return NULL; sd = (sort_data*)malloc(sizeof(sort_data)); sd->size = DEF_SIZE; sd->data = (int*)malloc(sizeof(int) * sd->size); sd->count = 0; fd = fopen(datafilename, "r"); if (fd == NULL) { printf("open file %s error.\n", datafilename); exit(0); } while ((rl = fread(buff, sizeof(char), BUFF_SIZE, fd)) > 0) { for (ri = 0; ri < rl; ri++) { if (buff[ri] == ',') { nbuf[bi] = '\0'; number = atoi(nbuf); add_number(sd, number); bi = 0; number = 0; } else { nbuf[bi] = buff[ri]; bi++; } } } if (bi != 0) { nbuf[bi+1] = '\0'; number = atoi(nbuf); add_number(sd, number); } return sd; }
// init 函数首先初始化屏幕,在方格中随机生成两个位置并放入随机数字2,4。 void init() { initscr(); cbreak(); noecho(); curs_set(0); empty = sizeof(a) / sizeof(a[0][0]); srand(time(0)); add_number(); add_number(); draw(); }
number_t mult_number(number_t a, number_t b) { number_t result; int i, k; result = string_to_number("0.0"); for (i = 0; i < b.digit_len; i++) { result = mult_one(10, result); result = add_number(result, mult_one(b.digit[i], a)); } k = b.digit_len - b.int_len; if (result.int_len > k) { result.int_len -= k; } else { for (i = result.digit_len - 1; i >= 0; i--) result.digit[i + k] = result.digit[i]; for (i = 0; i < k; i++) result.digit[i] = 0; result.digit_len += k; } result.sign *= b.sign; return remove_zeros(result); }
void numbersGenerator<de>::generate_all_numbers() { for( int i1 = 0; i1 <= max_val; ++i1 ) { int ipxx1 = i1 * i1; for( int i2 = 0; i2 <= max_val; ++i2 ) { int ipxx2 = ipxx1 + i2 * i2; if( ipxx2 > max_val2 ) break; for( int i3 = 0; i3 <= max_val; ++i3 ) { int ipxx3 = ipxx2 + i3 * i3; if( ipxx3 > max_val2 ) break; for( int i4 = 0; i4 <= max_val; ++i4 ) { int ipxx4 = ipxx3 + i4 * i4; if( ipxx4 > max_val2 ) break; add_number( i1, i2, i3, i4, ipxx4 ); } } } } }
/* * The wrapper for the function we want to trace. Records * input arguments and the result to the capture trace. */ static uint32_t add_number_wrapper(uint32_t a, uint32_t b) { enter_add_number_record_t enter_rec; exit_add_number_record_t exit_rec; uint32_t res; void* rec; enter_rec.id = enter_add_number; enter_rec.a = a; enter_rec.b = b; rtems_capture_begin_add_record(_Thread_Get_executing(), RTEMS_CAPTURE_TIMESTAMP, sizeof(rtems_capture_record_t)+ sizeof(enter_add_number_record_t), &rec); rec = rtems_capture_append_to_record(rec, &enter_rec, sizeof(enter_rec)); rtems_capture_end_add_record(rec); res = add_number(a, b); exit_rec.id = exit_add_number; exit_rec.res = res; rtems_capture_begin_add_record(_Thread_Get_executing(), RTEMS_CAPTURE_TIMESTAMP, sizeof(rtems_capture_record_t)+ sizeof(exit_add_number_record_t), &rec); rec = rtems_capture_append_to_record(rec, &exit_rec, sizeof(exit_rec)); rtems_capture_end_add_record(rec); return res; }
/* * Return a random number in the range 0..(n-1). */ unsigned int DefaultRndNumGenerator::rnd_upto(const unsigned int n, const Filter *f, const std::string *where) { static int g = 0; int h = g; if (h == 440) BREAK_NOP; // for debugging unsigned int v = genrand() % n; unsigned INT64 local_depth = rand_depth_; rand_depth_++; //ofstream out("rnd.log", ios_base::app); //out << g++ << ": " << v << "(" << n << ")" << endl; if (f) { while (f->filter(v)) { // We could add numbers into sequence inside the previous filter. // If the previous filter failed, we need to roll back the rand_depth_ here. // This will also overwrite the value added in the map. rand_depth_ = local_depth+1; v = genrand() % n; /*out << g++ << ": " << v << "(" << n << ")" << endl;*/ } } //out.close(); if (where) { std::ostringstream ss; ss << *where << "->"; trace_string_ += ss.str(); } add_number(v, n, local_depth); return v; }
/* tal_count() gives the length of the script. */ u8 *bitcoin_redeem_2of2(const tal_t *ctx, const struct pubkey *key1, const struct pubkey *key2) { u8 *script = tal_arr(ctx, u8, 0); add_number(&script, 2); if (key_less(key1, key2)) { add_push_key(&script, key1); add_push_key(&script, key2); } else { add_push_key(&script, key2); add_push_key(&script, key1); } add_number(&script, 2); add_op(&script, OP_CHECKMULTISIG); return script; }
int main(int argc, char *argv[]) { // char linebuf[BUFLEN]; add_number(1); add_number(13); add_number(8); add_number(8); get_head_and_del(); add_number(8); add_number(91); add_number(32); add_pre_number(19); get_head_and_del(); print_sorted(); delete_all(); return 0; }
// 用 wsad 来表示上下左右方向 void play() { int old_empty; char ch; while (1) { moved = 0; old_empty = empty; ch = getch(); switch (ch) { case 'A': case 'a': left(); break; case 'D': case 'd': right(); break; case 'W': case 'w': up(); break; case 'S': case 's': down(); break; case 'Q': case 'q': endflag = quit; break; default: continue; } draw(); // refresh // 游戏失败 if (empty <= 0 && test_lose()) { endflag = lose; } // 判断游戏结束条件 if (endflag != playing) { game_over(); } //生成新方块 if ((empty != old_empty) || (moved == 1)) { //修复了不移动或不消除方块也生成新方块的bug add_number(); draw(); } } }
int main(){ char result[MAX_BUFF]; int i; for(i=1; i < 100; i++) { clear(result); run_functions(i, result); add_number(i, result); printf("%s\n", result); } return 0; }
static void new_game(t_context *gamestate) { WINDOW **windows; windows = gamestate->windows; if (ft_bitscan(WIN_VALUE) != 1 || WIN_VALUE == 1) { mvwaddstr(windows[SCORE], CENTER(WINC_Y, 1), 2, "I AIN'T RUNNIN' THAT"); wrefresh(windows[SCORE]); gamestate->is_running = 0; return ; } gamestate->is_running = 1; mvwhline(windows[HIGHSCORES], WINA_Y - 2, 1, ' ', WINA_X - 2); wrefresh(windows[HIGHSCORES]); update_score(gamestate); gamestate->grid = new_grid(); add_number(gamestate); add_number(gamestate); draw_grid(gamestate); }
int main() { struct Node * list; add_number(&list,1); print(print_list, list); printf("\n"); add_number(&list,45); print(print_list, list); printf("\n"); add_number(&list,3); print(print_list, list); printf("\n"); add_number(&list,46); print(print_list, list); printf("\n"); add_number(&list,103); print(print_list, list); printf("\n"); clean_list(&list); }
int main(int argc,char* argv[]) { int num1,num2; int return_value; if(argc < 2){ printf("You need to enter two numbers to add.\n"); printf("add_num.exe num1 num2\n"); return 0; } num1 = atoi(argv[1]); num2 = atoi(argv[2]); return_value = add_number(num1,num2); printf("Sum of %d + %d = %d",num1,num2,return_value); return 0; }
static gchar* make_simple_trans_line (Account *acc, Transaction *trans, Split *split, CsvExportInfo *info) { gboolean t_void = xaccTransGetVoidStatus (trans); gchar *result = begin_trans_string (trans, info); result = add_account_name (result, acc, NULL, TRUE, info); result = add_number (result, trans, info); result = add_description (result, trans, info); result = add_category (result, split, TRUE, info); result = add_reconcile (result, split, info); result = add_amount (result, split, t_void, TRUE, TRANS_SIMPLE, info); result = add_amount (result, split, t_void, FALSE, TRANS_SIMPLE, info); result = add_rate (result, split, t_void, info); return result; }
number_t sub_number(number_t a, number_t b) { number_t r; int borrow, dif, i, t, m; r = zero(); if ((a.sign < 0) || (b.sign < 0)) { b.sign *= -1; r = add_number(a, b); return r; } if (compare_number(a, b) < 0) { r = sub_number(b, a); r.sign = -1; return r; } r.int_len = max(a.int_len, b.int_len); m = max(a.digit_len - a.int_len, b.digit_len - b.int_len); r.digit_len = r.int_len + m; borrow = 0; for (i = r.digit_len - 1; i >= 0; i--) { dif = -borrow; t = i - r.int_len + a.int_len; if (t < a.digit_len && t >= 0) dif += a.digit[t]; t = i - r.int_len + b.int_len; if (t < b.digit_len && t >= 0) dif -= b.digit[t]; if (dif < 0) { borrow = 1; dif += 10; } else borrow = 0; r.digit[i] = dif % 10; } return remove_zeros(r); }
void turn_right(t_box *box) { int y; y = 0; while (y <= (box->size - 1)) { move_number(box->tab[y], box); move_number(box->tab[y], box); move_number(box->tab[y], box); move_number(box->tab[y], box); add_number(box->tab[y], box); move_number(box->tab[y], box); move_number(box->tab[y], box); move_number(box->tab[y], box); move_number(box->tab[y], box); y++; } }
number_t mult_num(number_t a, number_t b) { number_t r, tmp; int i, j, t; r = zero(); t = b.digit_len - b.int_len; for (i = b.digit_len - 1, j = 0; i >= 0; i--, j++) { tmp = mult_one(b.digit[i], a); tmp = digit_shift(j, tmp); r = add_number(r, tmp); } r.int_len -= t; r.sign = a.sign * b.sign; return remove_zeros(r); }
int test() { number_t s, t, u, v, w, y, z, zero; s = string_to_number("1357.935"); t = string_to_number("-30000.00009"); u = string_to_number("99999.13579"); v = string_to_number("-8765789.9900899"); w = string_to_number("-1.00001"); y = string_to_number("0.0001"); z = string_to_number("-0.0000000001"); zero = string_to_number("0.0"); print_number(add_number(s, t)); printf("\n"); print_number(add_number(t, u)); printf("\n"); print_number(add_number(s, u)); printf("\n"); print_number(add_number(t, w)); printf("\n"); print_number(sub_number(s, t)); printf("\n"); print_number(sub_number(t, u)); printf("\n"); print_number(sub_number(t, t)); printf("\n"); print_number(sub_number(t, t)); printf("\n"); print_number(add_number(v, v)); printf("\n"); print_number(sub_number(v, s)); printf("\n"); print_number(mult_number(w, w)); printf("\n"); print_number(mult_number(z, w)); printf("\n"); print_number(mult_number(w, y)); printf("\n"); print_number(mult_one(3, w)); printf("\n"); print_number(add_number(zero, z)); printf("\n"); print_number(mult_number(w, w)); int i; scanf("%d", &i); }
number_t sub_number(number_t a, number_t b) { number_t result; int borrow, dif, i; if (a.sign != b.sign) { b.sign *= -1; return add_number(a, b); } if (a.sign < 0 && b.sign < 0) { a.sign = b.sign = 1; return sub_number(b, a); } if (compare_number(a, b) < 0) { result = sub_number(b, a); if (! (result.digit_len == 2 && result.digit[0] == 0 && result.digit[1] == 0)) result.sign = -1; return result; } result.sign = 1; result.int_len = max(a.int_len, b.int_len); result.digit_len = result.int_len + max(a.digit_len - a.int_len, b.digit_len - b.int_len); borrow = 0; for (i = result.digit_len - 1; i >= 0; i--) { dif = -borrow + digit_at(a, result.int_len - i - 1) - digit_at(b, result.int_len - i - 1); if (dif < 0) { borrow = 1; dif += 10; } else borrow = 0; result.digit[i] = dif % 10; } return remove_zeros(result); }
int main() { number_t a, r, two; int i; r = string_to_number("0.0"); two = string_to_number("5.0"); for (i = 0; i <= 100; i++) { a = make_exp(-i); while (1) { if (compare_number(mult_num(r, r), two) > 0) { r = sub_number(r, a); break; } r = add_number(r, a); } print_number(r); printf("\n"); } return 0; }
u8 *scriptsig_p2sh_2of2(const tal_t *ctx, const struct bitcoin_signature *sig1, const struct bitcoin_signature *sig2, const struct pubkey *key1, const struct pubkey *key2) { u8 *script = tal_arr(ctx, u8, 0); u8 *redeemscript; /* OP_CHECKMULTISIG has an out-by-one bug, which MBZ */ add_number(&script, 0); /* sig order should match key order. */ if (key_less(key1, key2)) { add_push_sig(&script, sig1); add_push_sig(&script, sig2); } else { add_push_sig(&script, sig2); add_push_sig(&script, sig1); } redeemscript = bitcoin_redeem_2of2(script, key1, key2); add_push_bytes(&script, redeemscript, tal_count(redeemscript)); return script; }
static gchar* make_complex_trans_line (Account *acc, Transaction *trans, Split *split, CsvExportInfo *info) { gboolean t_void = xaccTransGetVoidStatus (trans); gchar *result = begin_trans_string (trans, info); result = add_type (result, trans, info); result = add_second_date (result, trans, info); result = add_account_name (result, acc, NULL, FALSE, info); result = add_number (result, trans, info); result = add_description (result, trans, info); result = add_notes (result, trans, info); result = add_memo (result, split, info); result = add_category (result, split, TRUE, info); result = add_category (result, split, FALSE, info); result = add_line_type (result, TRANS_COMPLEX, info); result = add_action (result,split, TRANS_COMPLEX, info); result = add_reconcile (result, split, info); result = add_amount (result, split, t_void, TRUE, TRANS_COMPLEX, info); result = add_comm_mnemonic (result, trans, NULL, info); result = add_comm_namespace (result, trans, NULL, info); result = add_trans_eol (result, info); return result; }
int main() { int k = add_number(100); k+=add_number(100); printf("%d", k); return 0; }
/* Calbacks */ static void moko_contacts_add_contact (MokoContacts *contacts, EContact *e_contact) { MokoContactsPrivate *priv; MokoContact *m_contact = NULL; const gchar *name, *uid; GList *attributes, *params, *numbers; g_return_if_fail (MOKO_IS_CONTACTS (contacts)); g_return_if_fail (E_IS_CONTACT (e_contact)); priv = contacts->priv; uid = e_contact_get_const (e_contact, E_CONTACT_UID); if (g_hash_table_lookup (priv->uids, uid)) return; name = e_contact_get_const (e_contact, E_CONTACT_FULL_NAME); if (!name || (g_utf8_strlen (name, -1) <= 0)) name = "Unknown"; /* Create the contact & append to the list */ m_contact = g_new0 (MokoContact, 1); m_contact->name = g_strdup (name); m_contact->uid = g_strdup (uid); m_contact->photo = NULL; priv->contacts = g_list_append (priv->contacts, m_contact); g_hash_table_insert (priv->uids, g_strdup (uid), m_contact); /* Now go through the numbers,creating MokoNumber for them */ for (attributes = e_vcard_get_attributes (E_VCARD(e_contact)); attributes; attributes = attributes->next) { MokoContactEntry *entry; const gchar *phone; const char *attr; attr = e_vcard_attribute_get_name (attributes->data); if (!strcmp (attr, EVC_TEL)) { for (numbers = e_vcard_attribute_get_values (attributes->data); numbers; numbers = numbers->next) { phone = numbers->data; if (phone) { entry = g_new0 (MokoContactEntry, 1); params = e_vcard_attribute_get_param (attributes->data, "TYPE"); if (params) entry->desc = g_strdup (params->data); entry->number = normalize (phone); entry->contact = m_contact; priv->entries = g_list_append (priv->entries, (gpointer)entry); g_hash_table_insert (priv->prefixes, g_strdup (entry->number), (gpointer)entry); add_number (&priv->start, entry); } } } } }
/* * This routine assumes that the line is a valid Unicode Character Database * entry. */ static void read_cdata(FILE *in) { ac_uint4 i, lineno, skip, code, ccl_code; short wnum, neg, number[2], compat; char line[512], *s, *e; lineno = skip = 0; while (fgets(line, sizeof(line), in)) { if( (s=strchr(line, '\n')) ) *s = '\0'; lineno++; /* * Skip blank lines and lines that start with a '#'. */ if (line[0] == 0 || line[0] == '#') continue; /* * If lines need to be skipped, do it here. */ if (skip) { skip--; continue; } /* * Collect the code. The code can be up to 6 hex digits in length to * allow surrogates to be specified. */ for (s = line, i = code = 0; *s != ';' && i < 6; i++, s++) { code <<= 4; if (*s >= '0' && *s <= '9') code += *s - '0'; else if (*s >= 'A' && *s <= 'F') code += (*s - 'A') + 10; else if (*s >= 'a' && *s <= 'f') code += (*s - 'a') + 10; } /* * Handle the following special cases: * 1. 4E00-9FA5 CJK Ideographs. * 2. AC00-D7A3 Hangul Syllables. * 3. D800-DFFF Surrogates. * 4. E000-F8FF Private Use Area. * 5. F900-FA2D Han compatibility. * ...Plus additional ranges in newer Unicode versions... */ switch (code) { case 0x3400: /* CJK Ideograph Extension A */ add_range(0x3400, 0x4db5, "Lo", "L"); add_range(0x3400, 0x4db5, "Cp", 0); skip = 1; break; case 0x4e00: /* * The Han ideographs. */ add_range(0x4e00, 0x9fff, "Lo", "L"); /* * Add the characters to the defined category. */ add_range(0x4e00, 0x9fa5, "Cp", 0); skip = 1; break; case 0xac00: /* * The Hangul syllables. */ add_range(0xac00, 0xd7a3, "Lo", "L"); /* * Add the characters to the defined category. */ add_range(0xac00, 0xd7a3, "Cp", 0); skip = 1; break; case 0xd800: /* * Make a range of all surrogates and assume some default * properties. */ add_range(0x010000, 0x10ffff, "Cs", "L"); skip = 5; break; case 0xe000: /* * The Private Use area. Add with a default set of properties. */ add_range(0xe000, 0xf8ff, "Co", "L"); skip = 1; break; case 0xf900: /* * The CJK compatibility area. */ add_range(0xf900, 0xfaff, "Lo", "L"); /* * Add the characters to the defined category. */ add_range(0xf900, 0xfaff, "Cp", 0); skip = 1; break; case 0x20000: /* CJK Ideograph Extension B */ add_range(0x20000, 0x2a6d6, "Lo", "L"); add_range(0x20000, 0x2a6d6, "Cp", 0); skip = 1; break; case 0xf0000: /* Plane 15 private use */ add_range(0xf0000, 0xffffd, "Co", "L"); skip = 1; break; case 0x100000: /* Plane 16 private use */ add_range(0x100000, 0x10fffd, "Co", "L"); skip = 1; break; } if (skip) continue; /* * Add the code to the defined category. */ ordered_range_insert(code, "Cp", 2); /* * Locate the first character property field. */ for (i = 0; *s != 0 && i < 2; s++) { if (*s == ';') i++; } for (e = s; *e && *e != ';'; e++) ; ordered_range_insert(code, s, e - s); /* * Locate the combining class code. */ for (s = e; *s != 0 && i < 3; s++) { if (*s == ';') i++; } /* * Convert the combining class code from decimal. */ for (ccl_code = 0, e = s; *e && *e != ';'; e++) ccl_code = (ccl_code * 10) + (*e - '0'); /* * Add the code if it not 0. */ if (ccl_code != 0) ordered_ccl_insert(code, ccl_code); /* * Locate the second character property field. */ for (s = e; *s != 0 && i < 4; s++) { if (*s == ';') i++; } for (e = s; *e && *e != ';'; e++) ; ordered_range_insert(code, s, e - s); /* * Check for a decomposition. */ s = ++e; if (*s != ';') { compat = *s == '<'; if (compat) { /* * Skip compatibility formatting tag. */ while (*s++ != '>'); } /* * Collect the codes of the decomposition. */ for (dectmp_size = 0; *s != ';'; ) { /* * Skip all leading non-hex digits. */ while (!ishdigit(*s)) s++; for (dectmp[dectmp_size] = 0; ishdigit(*s); s++) { dectmp[dectmp_size] <<= 4; if (*s >= '0' && *s <= '9') dectmp[dectmp_size] += *s - '0'; else if (*s >= 'A' && *s <= 'F') dectmp[dectmp_size] += (*s - 'A') + 10; else if (*s >= 'a' && *s <= 'f') dectmp[dectmp_size] += (*s - 'a') + 10; } dectmp_size++; } /* * If there are any codes in the temporary decomposition array, * then add the character with its decomposition. */ if (dectmp_size > 0) { if (!compat) { add_decomp(code, 0); } add_decomp(code, 1); } } /* * Skip to the number field. */ for (i = 0; i < 3 && *s; s++) { if (*s == ';') i++; } /* * Scan the number in. */ number[0] = number[1] = 0; for (e = s, neg = wnum = 0; *e && *e != ';'; e++) { if (*e == '-') { neg = 1; continue; } if (*e == '/') { /* * Move the the denominator of the fraction. */ if (neg) number[wnum] *= -1; neg = 0; e++; wnum++; } number[wnum] = (number[wnum] * 10) + (*e - '0'); } if (e > s) { /* * Adjust the denominator in case of integers and add the number. */ if (wnum == 0) number[1] = 1; add_number(code, number[0], number[1]); } /* * Skip to the start of the possible case mappings. */ for (s = e, i = 0; i < 4 && *s; s++) { if (*s == ';') i++; } /* * Collect the case mappings. */ cases[0] = cases[1] = cases[2] = 0; for (i = 0; i < 3; i++) { while (ishdigit(*s)) { cases[i] <<= 4; if (*s >= '0' && *s <= '9') cases[i] += *s - '0'; else if (*s >= 'A' && *s <= 'F') cases[i] += (*s - 'A') + 10; else if (*s >= 'a' && *s <= 'f') cases[i] += (*s - 'a') + 10; s++; } if (*s == ';') s++; } if (cases[0] && cases[1]) /* * Add the upper and lower mappings for a title case character. */ add_title(code); else if (cases[1]) /* * Add the lower and title case mappings for the upper case * character. */ add_upper(code); else if (cases[0]) /* * Add the upper and title case mappings for the lower case * character. */ add_lower(code); } }
static void Init(rtems_task_argument arg) { rtems_status_code sc; uint32_t i; uint32_t cpu; uint32_t cpu_count; uint32_t read; uint32_t enter_count; uint32_t exit_count; uint32_t clock_tick_count; uint32_t res_should_be; rtems_name name; rtems_capture_record_t *recs; rtems_capture_record_t *prev_rec; empty_record_t *record; enter_add_number_record_t *enter_add_number_rec; exit_add_number_record_t *exit_add_number_rec; rtems_vector_number vec; clock_interrupt_handler cih = {.found = 0}; TEST_BEGIN(); /* Get the number of processors that we are using. */ cpu_count = rtems_get_processor_count(); sc = rtems_capture_open(50000, NULL); rtems_test_assert(sc == RTEMS_SUCCESSFUL); sc = rtems_capture_watch_global(true); rtems_test_assert(sc == RTEMS_SUCCESSFUL); sc = rtems_capture_control(true); rtems_test_assert(sc == RTEMS_SUCCESSFUL); /* Run main test */ test(cpu_count); /* Try to find the clock interrupt handler */ for ( vec=BSP_INTERRUPT_VECTOR_MIN; vec<BSP_INTERRUPT_VECTOR_MAX; vec++ ) { rtems_interrupt_handler_iterate(vec, locate_clock_interrupt_handler, &cih); if ( cih.found ) break; } /* If we find the clock interrupt handler we replace it with * a wrapper and wait for a fixed number of ticks. */ if ( cih.found ) { #ifdef VERBOSE printf("Found a clock handler\n"); #endif org_clock_handler = cih.handler; rtems_interrupt_handler_install(vec, cih.info, cih.options | RTEMS_INTERRUPT_REPLACE, clock_tick_wrapper, cih.arg); rtems_task_wake_after(CLOCK_TICKS); } /* Disable capturing */ sc = rtems_capture_control(false); rtems_test_assert(sc == RTEMS_SUCCESSFUL); clock_tick_count = 0; /* Read out the trace from all processors */ for ( cpu = 0; cpu < cpu_count; cpu++ ) { sc = rtems_capture_read(cpu, &read, &recs); rtems_test_assert(sc == RTEMS_SUCCESSFUL); prev_rec = recs; enter_count = 0; exit_count = 0; res_should_be = 0; for ( i = 0; i < read; i++ ) { /* Verify that time goes forward */ rtems_test_assert(recs->time>=prev_rec->time); if ( recs->events & RTEMS_CAPTURE_TIMESTAMP ) { record = (empty_record_t*)((char*) recs + sizeof(rtems_capture_record_t)); switch ( record->id ) { case enter_add_number: rtems_test_assert(enter_count==exit_count); enter_count++; enter_add_number_rec = (enter_add_number_record_t*)record; res_should_be = add_number(enter_add_number_rec->a, enter_add_number_rec->b); rtems_object_get_classic_name(recs->task_id, &name); #ifdef VERBOSE /* Print record */ printf("Time: %"PRIu64"us Task: %4s => Add %"PRIu32" and" " %"PRIu32"\n", recs->time/1000, (char*)&name, enter_add_number_rec->a, enter_add_number_rec->b); #endif break; case exit_add_number: rtems_test_assert(enter_count==exit_count+1); exit_count++; exit_add_number_rec = (exit_add_number_record_t*)record; /* Verify that the result matches the expected result */ rtems_test_assert(res_should_be == exit_add_number_rec->res); #ifdef VERBOSE /* Print record */ rtems_object_get_classic_name(recs->task_id, &name); printf("Time: %"PRIu64"us Task: %4s => Result is %"PRIu32"\n", recs->time/1000, (char*)&name, exit_add_number_rec->res); #endif break; case clock_tick: clock_tick_count++; #ifdef VERBOSE rtems_object_get_classic_name(recs->task_id, &name); printf("Time: %"PRIu64"us Task: %4s => Clock tick\n", recs->time/1000, (char*)&name); #endif break; default: rtems_test_assert(0); } } prev_rec = recs; recs = (rtems_capture_record_t*) ((char*) recs + recs->size); } rtems_test_assert(enter_count == exit_count); rtems_test_assert(enter_count == TASKS_PER_CPU * ITERATIONS); rtems_capture_release(cpu, read); } if( cih.found ) rtems_test_assert(clock_tick_count == cpu_count * CLOCK_TICKS); TEST_END(); rtems_test_exit(0); }
/** * We've found a '<' character. We ignore this if it is a comment or a * directive. If it is something else, then whatever it is we are looking * at is bogus. Returning NULL stops processing. * * @param[in] xml_name the name of an xml bracket (usually) * @param[in,out] res_val the option data derived from the XML element * * @returns the place to resume scanning input */ static char const * scan_xml(char const * xml_name, tOptionValue * res_val) { size_t nm_len, v_len; char const * scan; char const * val_str; tOptionValue valu; tOptionLoadMode save_mode = option_load_mode; if (! IS_VAR_FIRST_CHAR(*++xml_name)) return unnamed_xml(xml_name); /* * "scan_xml_name()" may change "option_load_mode". */ val_str = scan_xml_name(xml_name, &nm_len, &valu); if (val_str == NULL) goto bail_scan_xml; if (valu.valType == OPARG_TYPE_NONE) scan = val_str; else { if (option_load_mode != OPTION_LOAD_KEEP) val_str = SPN_WHITESPACE_CHARS(val_str); scan = find_end_xml(xml_name, nm_len, val_str, &v_len); if (scan == NULL) goto bail_scan_xml; } /* * "scan" now points to where the scan is to resume after returning. * It either points after "/>" at the end of the XML element header, * or it points after the "</name>" tail based on the name in the header. */ switch (valu.valType) { case OPARG_TYPE_NONE: add_string(&(res_val->v.nestVal), xml_name, nm_len, NULL, 0); break; case OPARG_TYPE_STRING: { tOptionValue * new_val = add_string( &(res_val->v.nestVal), xml_name, nm_len, val_str, v_len); if (option_load_mode != OPTION_LOAD_KEEP) munge_str(new_val->v.strVal, option_load_mode); break; } case OPARG_TYPE_BOOLEAN: add_bool(&(res_val->v.nestVal), xml_name, nm_len, val_str, v_len); break; case OPARG_TYPE_NUMERIC: add_number(&(res_val->v.nestVal), xml_name, nm_len, val_str, v_len); break; case OPARG_TYPE_HIERARCHY: { char * pz = AGALOC(v_len+1, "h scan"); memcpy(pz, val_str, v_len); pz[v_len] = NUL; add_nested(&(res_val->v.nestVal), xml_name, nm_len, pz, v_len); AGFREE(pz); break; } case OPARG_TYPE_ENUMERATION: case OPARG_TYPE_MEMBERSHIP: default: break; } option_load_mode = save_mode; return scan; bail_scan_xml: option_load_mode = save_mode; return NULL; }