gnunet_testing_ng_lib.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833
  1. /*
  2. This file is part of GNUnet
  3. Copyright (C) 2021 GNUnet e.V.
  4. GNUnet is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Affero General Public License as published
  6. by the Free Software Foundation, either version 3 of the License,
  7. or (at your option) any later version.
  8. GNUnet is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. SPDX-License-Identifier: AGPL3.0-or-later
  15. */
  16. /**
  17. * @brief API for writing an interpreter to test GNUnet components
  18. * @author Christian Grothoff <christian@grothoff.org>
  19. * @author Marcello Stanisci
  20. * @author t3sserakt
  21. */
  22. #ifndef GNUNET_TESTING_NG_LIB_H
  23. #define GNUNET_TESTING_NG_LIB_H
  24. #include "gnunet_util_lib.h"
  25. /* ********************* Helper functions ********************* */
  26. /**
  27. * Print failing line number and trigger shutdown. Useful
  28. * quite any time after the command "run" method has been called.
  29. */
  30. #define GNUNET_TESTING_FAIL(is) \
  31. do \
  32. { \
  33. GNUNET_break (0); \
  34. GNUNET_TESTING_interpreter_fail (is); \
  35. return; \
  36. } while (0)
  37. /* ******************* Generic interpreter logic ************ */
  38. /**
  39. * Global state of the interpreter, used by a command
  40. * to access information about other commands.
  41. */
  42. struct GNUNET_TESTING_Interpreter;
  43. /**
  44. * A command to be run by the interpreter.
  45. */
  46. struct GNUNET_TESTING_Command
  47. {
  48. /**
  49. * Closure for all commands with command-specific context information.
  50. */
  51. void *cls;
  52. /**
  53. * Label for the command.
  54. */
  55. const char *label;
  56. /**
  57. * Runs the command. Note that upon return, the interpreter
  58. * will not automatically run the next command, as the command
  59. * may continue asynchronously in other scheduler tasks. Thus,
  60. * the command must ensure to eventually call
  61. * #GNUNET_TESTING_interpreter_next() or
  62. * #GNUNET_TESTING_interpreter_fail().
  63. *
  64. * If this function creates some asynchronous activity, it should
  65. * initialize @e finish to a function that can be used to wait for
  66. * the asynchronous activity to terminate.
  67. *
  68. * @param cls closure
  69. * @param cmd command being run
  70. * @param i interpreter state
  71. */
  72. void
  73. (*run)(void *cls,
  74. const struct GNUNET_TESTING_Command *cmd,
  75. struct GNUNET_TESTING_Interpreter *i);
  76. /**
  77. * Wait for any asynchronous execution of @e run to conclude,
  78. * then call finish_cont. Finish may only be called once per command.
  79. *
  80. * This member may be NULL if this command is a synchronous command,
  81. * and also should be set to NULL once the command has finished.
  82. *
  83. * @param cls closure
  84. * @param cont function to call upon completion, can be NULL
  85. * @param cont_cls closure for @a cont
  86. */
  87. bool
  88. (*finish)(void *cls,
  89. GNUNET_SCHEDULER_TaskCallback cont,
  90. void *cont_cls);
  91. /**
  92. * Task for running the finish function.
  93. */
  94. struct GNUNET_SCHEDULER_Task *finish_task;
  95. /**
  96. * Clean up after the command. Run during forced termination
  97. * (CTRL-C) or test failure or test success.
  98. *
  99. * @param cls closure
  100. * @param cmd command being cleaned up
  101. */
  102. void
  103. (*cleanup)(void *cls,
  104. const struct GNUNET_TESTING_Command *cmd);
  105. /**
  106. * Extract information from a command that is useful for other
  107. * commands.
  108. *
  109. * @param cls closure
  110. * @param[out] ret result (could be anything)
  111. * @param trait name of the trait
  112. * @param index index number of the object to extract.
  113. * @return #GNUNET_OK on success
  114. */
  115. int
  116. (*traits)(void *cls,
  117. const void **ret,
  118. const char *trait,
  119. unsigned int index);
  120. /**
  121. * When did the execution of this command start?
  122. */
  123. struct GNUNET_TIME_Absolute start_time;
  124. /**
  125. * When did the execution of this command finish?
  126. */
  127. struct GNUNET_TIME_Absolute finish_time;
  128. /**
  129. * When did we start the last run of this command? Delta to @e finish_time
  130. * gives the latency for the last successful run. Useful in case @e
  131. * num_tries was positive and the command was run multiple times. In that
  132. * case, the @e start_time gives the time when we first tried to run the
  133. * command, so the difference between @e start_time and @e finish_time would
  134. * be the time all of the @e num_tries took, while the delta to @e
  135. * last_req_time is the time the last (successful) execution took.
  136. */
  137. struct GNUNET_TIME_Absolute last_req_time;
  138. /**
  139. * How often did we try to execute this command? (In case it is a request
  140. * that is repated.) Note that a command must have some build-in retry
  141. * mechanism for this value to be useful.
  142. */
  143. unsigned int num_tries;
  144. /**
  145. * In case @e asynchronous_finish is true, how long should we wait for this
  146. * command to complete? If @e finish did not complete after this amount of
  147. * time, the interpreter will fail. Should be set generously to ensure
  148. * tests do not fail on slow systems.
  149. */
  150. struct GNUNET_TIME_Relative default_timeout;
  151. /**
  152. * If "true", the interpreter should not immediately call
  153. * @e finish, even if @e finish is non-NULL. Otherwise,
  154. * #TALER_TESTING_cmd_finish() must be used
  155. * to ensure that a command actually completed.
  156. */
  157. bool asynchronous_finish;
  158. };
  159. /**
  160. * Struct to use for command-specific context information closure of a command waiting
  161. * for another command.
  162. */
  163. struct SyncState
  164. {
  165. /**
  166. * Closure for all commands with command-specific context information.
  167. */
  168. void *cls;
  169. /**
  170. * The asynchronous command the synchronous command of this closure waits for.
  171. */
  172. const struct GNUNET_TESTING_Command *async_cmd;
  173. /**
  174. * Task for running the finish method of the asynchronous task the command is waiting for.
  175. */
  176. struct GNUNET_SCHEDULER_Task *finish_task;
  177. /**
  178. * When did the execution of this commands finish function start?
  179. */
  180. struct GNUNET_TIME_Absolute start_finish_time;
  181. };
  182. /**
  183. * Lookup command by label.
  184. *
  185. * @param label label of the command to lookup.
  186. * @return the command, if it is found, or NULL.
  187. */
  188. const struct GNUNET_TESTING_Command *
  189. GNUNET_TESTING_interpreter_lookup_command (
  190. const char *label);
  191. /**
  192. * Obtain label of the command being now run.
  193. *
  194. * @param is interpreter state.
  195. * @return the label.
  196. */
  197. const char *
  198. GNUNET_TESTING_interpreter_get_current_label (
  199. struct GNUNET_TESTING_Interpreter *is);
  200. /**
  201. * Current command failed, clean up and fail the test case.
  202. *
  203. * @param is interpreter state.
  204. */
  205. void
  206. GNUNET_TESTING_interpreter_fail (struct GNUNET_TESTING_Interpreter *is);
  207. /**
  208. * Create command array terminator.
  209. *
  210. * @return a end-command.
  211. */
  212. struct GNUNET_TESTING_Command
  213. GNUNET_TESTING_cmd_end (void);
  214. /**
  215. * Turn asynchronous command into non blocking command by setting asynchronous_finish to true.
  216. *
  217. * @param cmd command to make synchronous.
  218. * @return a finish-command.
  219. */
  220. const struct GNUNET_TESTING_Command
  221. GNUNET_TESTING_cmd_make_unblocking (const struct GNUNET_TESTING_Command cmd);
  222. /**
  223. * Create (synchronous) command that waits for another command to finish.
  224. * If @a cmd_ref did not finish after @a timeout, this command will fail
  225. * the test case.
  226. *
  227. * @param finish_label label for this command
  228. * @param cmd_ref reference to a previous command which we should
  229. * wait for (call `finish()` on)
  230. * @param timeout how long to wait at most for @a cmd_ref to finish
  231. * @return a finish-command.
  232. */
  233. const struct GNUNET_TESTING_Command
  234. GNUNET_TESTING_cmd_finish (const char *finish_label,
  235. const char *cmd_ref,
  236. struct GNUNET_TIME_Relative timeout);
  237. /**
  238. * Make the instruction pointer point to @a target_label
  239. * only if @a counter is greater than zero.
  240. *
  241. * @param label command label
  242. * @param target_label label of the new instruction pointer's destination after the jump;
  243. * must be before the current instruction
  244. * @param counter counts how many times the rewinding is to happen.
  245. */
  246. struct GNUNET_TESTING_Command
  247. GNUNET_TESTING_cmd_rewind_ip (const char *label,
  248. const char *target_label,
  249. unsigned int counter);
  250. /**
  251. * Wait until we receive SIGCHLD signal. Then obtain the process trait of the
  252. * current command, wait on the the zombie and continue with the next command.
  253. *
  254. * @param is interpreter state.
  255. */
  256. // void
  257. // GNUNET_TESTING_wait_for_sigchld (struct GNUNET_TESTING_Interpreter *is);
  258. // => replace with child_management.c
  259. /**
  260. * Start scheduling loop with signal handlers and run the
  261. * test suite with the @a commands.
  262. *
  263. * @param cfg_name name of configuration file to use
  264. * @param commands the list of command to execute
  265. * @param timeout how long to wait for each command to execute
  266. * @return #GNUNET_OK if all is okay, != #GNUNET_OK otherwise.
  267. * non-GNUNET_OK codes are #GNUNET_SYSERR most of the
  268. * times.
  269. */
  270. int
  271. GNUNET_TESTING_run (const char *cfg_filename,
  272. struct GNUNET_TESTING_Command *commands,
  273. struct GNUNET_TIME_Relative timeout);
  274. /**
  275. * Look for substring in a programs' name.
  276. *
  277. * @param prog program's name to look into
  278. * @param marker chunk to find in @a prog
  279. */
  280. int
  281. GNUNET_TESTING_has_in_name (const char *prog,
  282. const char *marker);
  283. /* ************** Specific interpreter commands ************ */
  284. /**
  285. * Create a "signal" CMD.
  286. *
  287. * @param label command label.
  288. * @param process_label label of a command that has a process trait
  289. * @param process_index index of the process trait at @a process_label
  290. * @param signal signal to send to @a process.
  291. * @return the command.
  292. */
  293. struct GNUNET_TESTING_Command
  294. GNUNET_TESTING_cmd_signal (const char *label,
  295. const char *process_label,
  296. unsigned int process_index,
  297. int signal);
  298. /**
  299. * Sleep for @a duration.
  300. *
  301. * @param label command label.
  302. * @param duration time to sleep
  303. * @return the command.
  304. */
  305. struct GNUNET_TESTING_Command
  306. GNUNET_TESTING_cmd_sleep (const char *label,
  307. struct GNUNET_TIME_Relative duration);
  308. /**
  309. * Create a "batch" command. Such command takes a end_CMD-terminated array of
  310. * CMDs and executed them. Once it hits the end CMD, it passes the control to
  311. * the next top-level CMD, regardless of it being another batch or ordinary
  312. * CMD.
  313. *
  314. * @param label the command label.
  315. * @param batch array of CMDs to execute.
  316. * @return the command.
  317. */
  318. struct GNUNET_TESTING_Command
  319. GNUNET_TESTING_cmd_batch (const char *label,
  320. struct GNUNET_TESTING_Command *batch);
  321. /**
  322. * Test if this command is a batch command.
  323. *
  324. * @return false if not, true if it is a batch command
  325. */
  326. // TODO: figure out if this needs to be exposed in the public API.
  327. int
  328. GNUNET_TESTING_cmd_is_batch (const struct GNUNET_TESTING_Command *cmd);
  329. /**
  330. * Advance internal pointer to next command.
  331. *
  332. * @param is interpreter state.
  333. */
  334. // TODO: figure out if this needs to be exposed in the public API.
  335. void
  336. GNUNET_TESTING_cmd_batch_next (struct GNUNET_TESTING_Interpreter *is);
  337. /**
  338. * Obtain what command the batch is at.
  339. *
  340. * @return cmd current batch command
  341. */
  342. // TODO: figure out if this needs to be exposed in the public API.
  343. struct GNUNET_TESTING_Command *
  344. GNUNET_TESTING_cmd_batch_get_current (const struct GNUNET_TESTING_Command *cmd);
  345. /**
  346. * Set what command the batch should be at.
  347. *
  348. * @param cmd current batch command
  349. * @param new_ip where to move the IP
  350. */
  351. // TODO: figure out if this needs to be exposed in the public API.
  352. void
  353. GNUNET_TESTING_cmd_batch_set_current (const struct GNUNET_TESTING_Command *cmd,
  354. unsigned int new_ip);
  355. /**
  356. * Performance counter.
  357. */
  358. struct GNUNET_TESTING_Timer
  359. {
  360. /**
  361. * For which type of commands.
  362. */
  363. const char *prefix;
  364. /**
  365. * Total time spend in all commands of this type.
  366. */
  367. struct GNUNET_TIME_Relative total_duration;
  368. /**
  369. * Total time spend waiting for the *successful* exeuction
  370. * in all commands of this type.
  371. */
  372. struct GNUNET_TIME_Relative success_latency;
  373. /**
  374. * Number of commands summed up.
  375. */
  376. unsigned int num_commands;
  377. /**
  378. * Number of retries summed up.
  379. */
  380. unsigned int num_retries;
  381. };
  382. /**
  383. * Obtain performance data from the interpreter.
  384. *
  385. * @param timers what commands (by label) to obtain runtimes for
  386. * @return the command
  387. */
  388. struct GNUNET_TESTING_Command
  389. GNUNET_TESTING_cmd_stat (struct GNUNET_TESTING_Timer *timers);
  390. /* *** Generic trait logic for implementing traits ********* */
  391. /**
  392. * A trait.
  393. */
  394. struct GNUNET_TESTING_Trait
  395. {
  396. /**
  397. * Index number associated with the trait. This gives the
  398. * possibility to have _multiple_ traits on offer under the
  399. * same name.
  400. */
  401. unsigned int index;
  402. /**
  403. * Trait type, for example "reserve-pub" or "coin-priv".
  404. */
  405. const char *trait_name;
  406. /**
  407. * Pointer to the piece of data to offer.
  408. */
  409. const void *ptr;
  410. };
  411. /**
  412. * "end" trait. Because traits are offered into arrays,
  413. * this type of trait is used to mark the end of such arrays;
  414. * useful when iterating over those.
  415. */
  416. struct GNUNET_TESTING_Trait
  417. GNUNET_TESTING_trait_end (void);
  418. /**
  419. * Extract a trait.
  420. *
  421. * @param traits the array of all the traits.
  422. * @param[out] ret where to store the result.
  423. * @param trait type of the trait to extract.
  424. * @param index index number of the trait to extract.
  425. * @return #GNUNET_OK when the trait is found.
  426. */
  427. int
  428. GNUNET_TESTING_get_trait (const struct GNUNET_TESTING_Trait *traits,
  429. const void **ret,
  430. const char *trait,
  431. unsigned int index);
  432. /* ****** Specific traits supported by this component ******* */
  433. /**
  434. * Obtain location where a command stores a pointer to a process.
  435. *
  436. * @param cmd command to extract trait from.
  437. * @param index which process to pick if @a cmd
  438. * has multiple on offer.
  439. * @param[out] processp set to the address of the pointer to the
  440. * process.
  441. * @return #GNUNET_OK on success.
  442. */
  443. int
  444. GNUNET_TESTING_get_trait_process (const struct GNUNET_TESTING_Command *cmd,
  445. unsigned int index,
  446. struct GNUNET_OS_Process ***processp);
  447. /**
  448. * Offer location where a command stores a pointer to a process.
  449. *
  450. * @param index offered location index number, in case there are
  451. * multiple on offer.
  452. * @param processp process location to offer.
  453. * @return the trait.
  454. */
  455. struct GNUNET_TESTING_Trait
  456. GNUNET_TESTING_make_trait_process (unsigned int index,
  457. struct GNUNET_OS_Process **processp);
  458. /**
  459. * Offer number trait, 32-bit version.
  460. *
  461. * @param index the number's index number.
  462. * @param n number to offer.
  463. */
  464. struct GNUNET_TESTING_Trait
  465. GNUNET_TESTING_make_trait_uint32 (unsigned int index,
  466. const uint32_t *n);
  467. /**
  468. * Obtain a "number" value from @a cmd, 32-bit version.
  469. *
  470. * @param cmd command to extract the number from.
  471. * @param index the number's index number.
  472. * @param[out] n set to the number coming from @a cmd.
  473. * @return #GNUNET_OK on success.
  474. */
  475. int
  476. GNUNET_TESTING_get_trait_uint32 (const struct GNUNET_TESTING_Command *cmd,
  477. unsigned int index,
  478. const uint32_t **n);
  479. /**
  480. * Offer number trait, 64-bit version.
  481. *
  482. * @param index the number's index number.
  483. * @param n number to offer.
  484. */
  485. struct GNUNET_TESTING_Trait
  486. GNUNET_TESTING_make_trait_uint64 (unsigned int index,
  487. const uint64_t *n);
  488. /**
  489. * Obtain a "number" value from @a cmd, 64-bit version.
  490. *
  491. * @param cmd command to extract the number from.
  492. * @param index the number's index number.
  493. * @param[out] n set to the number coming from @a cmd.
  494. * @return #GNUNET_OK on success.
  495. */
  496. int
  497. GNUNET_TESTING_get_trait_uint64 (const struct GNUNET_TESTING_Command *cmd,
  498. unsigned int index,
  499. const uint64_t **n);
  500. /**
  501. * Offer number trait, 64-bit signed version.
  502. *
  503. * @param index the number's index number.
  504. * @param n number to offer.
  505. */
  506. struct GNUNET_TESTING_Trait
  507. GNUNET_TESTING_make_trait_int64 (unsigned int index,
  508. const int64_t *n);
  509. /**
  510. * Obtain a "number" value from @a cmd, 64-bit signed version.
  511. *
  512. * @param cmd command to extract the number from.
  513. * @param index the number's index number.
  514. * @param[out] n set to the number coming from @a cmd.
  515. * @return #GNUNET_OK on success.
  516. */
  517. int
  518. GNUNET_TESTING_get_trait_int64 (const struct GNUNET_TESTING_Command *cmd,
  519. unsigned int index,
  520. const int64_t **n);
  521. /**
  522. * Offer a number.
  523. *
  524. * @param index the number's index number.
  525. * @param n the number to offer.
  526. * @return #GNUNET_OK on success.
  527. */
  528. struct GNUNET_TESTING_Trait
  529. GNUNET_TESTING_make_trait_uint (unsigned int index,
  530. const unsigned int *i);
  531. /**
  532. * Obtain a number from @a cmd.
  533. *
  534. * @param cmd command to extract the number from.
  535. * @param index the number's index number.
  536. * @param[out] n set to the number coming from @a cmd.
  537. * @return #GNUNET_OK on success.
  538. */
  539. int
  540. GNUNET_TESTING_get_trait_uint (const struct GNUNET_TESTING_Command *cmd,
  541. unsigned int index,
  542. const unsigned int **n);
  543. /**
  544. * Obtain a string from @a cmd.
  545. *
  546. * @param cmd command to extract the subject from.
  547. * @param index index number associated with the transfer
  548. * subject to offer.
  549. * @param[out] s where to write the offered
  550. * string.
  551. * @return #GNUNET_OK on success.
  552. */
  553. int
  554. GNUNET_TESTING_get_trait_string (
  555. const struct GNUNET_TESTING_Command *cmd,
  556. unsigned int index,
  557. const char **s);
  558. /**
  559. * Offer string subject.
  560. *
  561. * @param index index number associated with the transfer
  562. * subject being offered.
  563. * @param s string to offer.
  564. * @return the trait.
  565. */
  566. struct GNUNET_TESTING_Trait
  567. GNUNET_TESTING_make_trait_string (unsigned int index,
  568. const char *s);
  569. /**
  570. * Offer a command in a trait.
  571. *
  572. * @param index always zero. Commands offering this
  573. * kind of traits do not need this index. For
  574. * example, a "meta" CMD returns always the
  575. * CMD currently being executed.
  576. * @param cmd wire details to offer.
  577. *
  578. * @return the trait.
  579. */
  580. struct GNUNET_TESTING_Trait
  581. GNUNET_TESTING_make_trait_cmd (unsigned int index,
  582. const struct GNUNET_TESTING_Command *cmd);
  583. /**
  584. * Obtain a command from @a cmd.
  585. *
  586. * @param cmd command to extract the command from.
  587. * @param index always zero. Commands offering this
  588. * kind of traits do not need this index. For
  589. * example, a "meta" CMD returns always the
  590. * CMD currently being executed.
  591. * @param[out] _cmd where to write the wire details.
  592. * @return #GNUNET_OK on success.
  593. */
  594. int
  595. GNUNET_TESTING_get_trait_cmd (const struct GNUNET_TESTING_Command *cmd,
  596. unsigned int index,
  597. struct GNUNET_TESTING_Command **_cmd);
  598. /**
  599. * Obtain a uuid from @a cmd.
  600. *
  601. * @param cmd command to extract the uuid from.
  602. * @param index which amount to pick if @a cmd has multiple
  603. * on offer
  604. * @param[out] uuid where to write the uuid.
  605. * @return #GNUNET_OK on success.
  606. */
  607. int
  608. GNUNET_TESTING_get_trait_uuid (const struct GNUNET_TESTING_Command *cmd,
  609. unsigned int index,
  610. struct GNUNET_Uuid **uuid);
  611. /**
  612. * Offer a uuid in a trait.
  613. *
  614. * @param index which uuid to offer, in case there are
  615. * multiple available.
  616. * @param uuid the uuid to offer.
  617. *
  618. * @return the trait.
  619. */
  620. struct GNUNET_TESTING_Trait
  621. GNUNET_TESTING_make_trait_uuid (unsigned int index,
  622. const struct GNUNET_Uuid *uuid);
  623. /**
  624. * Obtain a absolute time from @a cmd.
  625. *
  626. * @param cmd command to extract trait from
  627. * @param index which time stamp to pick if
  628. * @a cmd has multiple on offer.
  629. * @param[out] time set to the wanted WTID.
  630. * @return #GNUNET_OK on success
  631. */
  632. int
  633. GNUNET_TESTING_get_trait_absolute_time (
  634. const struct GNUNET_TESTING_Command *cmd,
  635. unsigned int index,
  636. const struct GNUNET_TIME_Absolute **time);
  637. /**
  638. * Offer a absolute time.
  639. *
  640. * @param index associate the object with this index
  641. * @param time which object should be returned
  642. * @return the trait.
  643. */
  644. struct GNUNET_TESTING_Trait
  645. GNUNET_TESTING_make_trait_absolute_time (
  646. unsigned int index,
  647. const struct GNUNET_TIME_Absolute *time);
  648. /**
  649. * Obtain a relative time from @a cmd.
  650. *
  651. * @param cmd command to extract trait from
  652. * @param index which time to pick if
  653. * @a cmd has multiple on offer.
  654. * @param[out] time set to the wanted WTID.
  655. * @return #GNUNET_OK on success
  656. */
  657. int
  658. GNUNET_TESTING_get_trait_relative_time (
  659. const struct GNUNET_TESTING_Command *cmd,
  660. unsigned int index,
  661. const struct GNUNET_TIME_Relative **time);
  662. /**
  663. * Offer a relative time.
  664. *
  665. * @param index associate the object with this index
  666. * @param time which object should be returned
  667. * @return the trait.
  668. */
  669. struct GNUNET_TESTING_Trait
  670. GNUNET_TESTING_make_trait_relative_time (
  671. unsigned int index,
  672. const struct GNUNET_TIME_Relative *time);
  673. /**
  674. * Create command.
  675. *
  676. * @param label name for command.
  677. * @param now when the command was started.
  678. * @return command.
  679. */
  680. struct GNUNET_TESTING_Command
  681. GNUNET_TESTING_cmd_hello_world_birth (const char *label,
  682. struct GNUNET_TIME_Absolute *now);
  683. /**
  684. * Create command.
  685. *
  686. * @param label name for command.
  687. * @param message initial message.
  688. * @return command.
  689. */
  690. struct GNUNET_TESTING_Command
  691. GNUNET_TESTING_cmd_hello_world (const char *label,
  692. const char *birthLabel,
  693. char *message);
  694. /**
  695. * Offer data from trait
  696. *
  697. * @param cmd command to extract the url from.
  698. * @param pt which url is to be picked, in case
  699. * multiple are offered.
  700. * @param[out] url where to write the url.
  701. * @return #GNUNET_OK on success.
  702. */
  703. int
  704. GNUNET_TESTING_get_trait_what_am_i (const struct GNUNET_TESTING_Command *cmd,
  705. char **what_am_i);
  706. #endif