PageRenderTime 52ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/usr/src/suites/os/smf/tests/libscf-low/lib/libscftest-templates.c

https://bitbucket.org/illumos/illumos-stc
C | 2991 lines | 1854 code | 232 blank | 905 comment | 690 complexity | 0a99059235dab8ed405f6e7239b9ce63 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception

Large files files are truncated, but you can click here to view the full file

  1. /*
  2. * CDDL HEADER START
  3. *
  4. * The contents of this file are subject to the terms of the
  5. * Common Development and Distribution License (the "License").
  6. * You may not use this file except in compliance with the License.
  7. *
  8. * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  9. * or http://www.opensolaris.org/os/licensing.
  10. * See the License for the specific language governing permissions
  11. * and limitations under the License.
  12. *
  13. * When distributing Covered Code, include this CDDL HEADER in each
  14. * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15. * If applicable, add the following below this CDDL HEADER, with the
  16. * fields enclosed by brackets "[]" replaced with your own identifying
  17. * information: Portions Copyright [yyyy] [name of copyright owner]
  18. *
  19. * CDDL HEADER END
  20. */
  21. /*
  22. *
  23. * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
  24. * Use is subject to license terms.
  25. */
  26. #pragma ident "%Z%%M% %I% %E% SMI"
  27. /*
  28. * libscftest-property:
  29. * A library of test routines used in the property tests
  30. * for the mid level libscf API.
  31. * All functions in this file and in the accompanying include file
  32. * (must) have names begin with the string "scftest_".
  33. */
  34. #include <errno.h>
  35. #include <stdio.h>
  36. #include <stdlib.h>
  37. #include <string.h>
  38. #include <strings.h>
  39. #include <unistd.h>
  40. #include <libscf.h>
  41. #include <libscf_priv.h>
  42. #include <libscftest-tmpl.h>
  43. #include <libscftest-low.h>
  44. /*
  45. * =====================================================
  46. * TEMPLATE FUNCTIONS
  47. * =====================================================
  48. */
  49. /*
  50. * scftest_tmpl_get_by_pg
  51. * Purpose: Call scf_tmpl_get_by_pg()
  52. * Parameters:
  53. * input: scf_propertygroup_t *pg; a property group to get
  54. * the template for
  55. * scf_pg_tmpl_t *template; a property group template
  56. * int flags: scf_tmpl_get_by_pg flags
  57. * scf_error_t *exp_err: the expected scf error code
  58. * output: none
  59. * Returns: The result of the scf_tmpl_get_by_pg call with PASS
  60. * or FAIL in the exp_err pointer.
  61. */
  62. int
  63. scftest_tmpl_get_by_pg(scf_propertygroup_t *pg, scf_pg_tmpl_t *template,
  64. int flags, scf_error_t *exp_err) {
  65. scf_error_t scf_err = SCF_ERROR_NONE;
  66. int scf_ret;
  67. if (*exp_err != SCF_ERROR_NONE) {
  68. (void) fprintf(stdout, "--INFO: "
  69. "Call scf_tmpl_get_by_pg() and expect an error\n");
  70. } else {
  71. (void) fprintf(stdout, "--INFO: "
  72. "Call scf_tmpl_get_by_pg() and return the "
  73. "pg template\n");
  74. }
  75. scf_ret = scf_tmpl_get_by_pg(pg, template, flags);
  76. scf_err = scf_error();
  77. /*
  78. * Check the returned data and expected error.
  79. */
  80. if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
  81. /*
  82. * An error was expected check that the error returned
  83. * matches the expected error and report anomalies as
  84. * well as success.
  85. */
  86. if (scf_err != *exp_err) {
  87. (void) fprintf(stdout, "--DIAG: "
  88. "scf_tmpl_get_by_pg() returned the "
  89. "wrong error\n\t"
  90. "EXPECTED: %u (%s)\n\t"
  91. "RETURNED: %u (%s)\n",
  92. (unsigned int)*exp_err, scf_strerror(*exp_err),
  93. (unsigned int)scf_err, scf_strerror(scf_err));
  94. *exp_err = FAIL;
  95. } else {
  96. (void) fprintf(stdout, "--INFO: "
  97. "scf_tmpl_get_by_pg() failed as expected %d\n",
  98. *exp_err);
  99. *exp_err = PASS;
  100. }
  101. } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
  102. /*
  103. * An error was expected but the template came back as
  104. * non-null which it should not have, therefore report
  105. * the anomaly.
  106. */
  107. (void) fprintf(stdout, "--DIAG: "
  108. "scf_tmpl_get_by_pg() did not fail as expected\n"
  109. "\tRETURNED: %d\n"
  110. "\tSCF_ERROR: %s\n", scf_ret,
  111. scf_strerror(scf_error()));
  112. *exp_err = FAIL;
  113. } else if (scf_ret == -1) {
  114. /*
  115. * No error was expected, and template is still NULL
  116. * report the anomaly.
  117. */
  118. (void) fprintf(stdout, "--DIAG: "
  119. "scf_tmpl_get_by_pg() returned an error\n"
  120. "\tERROR: %u (%s)\n",
  121. (unsigned int)scf_err, scf_strerror(scf_err));
  122. *exp_err = FAIL;
  123. } else {
  124. *exp_err = PASS;
  125. }
  126. return (scf_ret);
  127. }
  128. /*
  129. * scftest_tmpl_get_by_pg_name
  130. * Purpose: Call scf_tmpl_get_by_pg_name()
  131. * Parameters:
  132. * input: scf_handle_t *h; a handle
  133. * const char *fmri: an instance
  134. * const char *snapshot: a snapshot name
  135. * const char *pg: a property group
  136. * int flags: scf_tmpl_get_by_pg flags
  137. * scf_error_t *exp_err: the expected scf error code
  138. * output: none
  139. * Returns: The result of the scf_tmpl_get_by_pg_name call with PASS
  140. * or FAIL in the exp_err pointer.
  141. */
  142. int
  143. scftest_tmpl_get_by_pg_name(const char *fmri, const char *snapshot,
  144. const char *pg_name, const char *pg_type, scf_pg_tmpl_t *template,
  145. int flags, scf_error_t *exp_err) {
  146. scf_error_t scf_err = SCF_ERROR_NONE;
  147. int scf_ret;
  148. if (*exp_err != SCF_ERROR_NONE) {
  149. (void) fprintf(stdout, "--INFO: "
  150. "Call scf_tmpl_get_by_pg_name() and expect an error\n");
  151. } else {
  152. (void) fprintf(stdout, "--INFO: "
  153. "Call scf_tmpl_get_by_pg_name() and return the "
  154. "pg template\n");
  155. }
  156. scf_ret = scf_tmpl_get_by_pg_name(fmri, snapshot, pg_name, pg_type,
  157. template, flags);
  158. scf_err = scf_error();
  159. /*
  160. * Check the returned data and expected error.
  161. */
  162. if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
  163. /*
  164. * An error was expected check that the error returned
  165. * matches the expected error and report anomalies as
  166. * well as success.
  167. */
  168. if (scf_err != *exp_err) {
  169. (void) fprintf(stdout, "--DIAG: "
  170. "scf_tmpl_get_by_pg_name() returned the "
  171. "wrong error\n\t"
  172. "EXPECTED: %u (%s)\n\t"
  173. "RETURNED: %u (%s)\n",
  174. (unsigned int)*exp_err, scf_strerror(*exp_err),
  175. (unsigned int)scf_err, scf_strerror(scf_err));
  176. *exp_err = FAIL;
  177. } else {
  178. (void) fprintf(stdout, "--INFO: "
  179. "scf_tmpl_get_by_pg_name() failed as expected %d\n",
  180. *exp_err);
  181. *exp_err = PASS;
  182. }
  183. } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
  184. /*
  185. * An error was expected but the template came back as
  186. * non-null which it should not have, therefore report
  187. * the anomaly.
  188. */
  189. (void) fprintf(stdout, "--DIAG: "
  190. "scf_tmpl_get_by_pg_name() did not fail as expected\n"
  191. "\tRETURNED: %d\n"
  192. "\tSCF_ERROR: %s\n", scf_ret,
  193. scf_strerror(scf_error()));
  194. *exp_err = FAIL;
  195. } else if (scf_ret == -1) {
  196. /*
  197. * No error was expected, and template is still NULL
  198. * report the anomaly.
  199. */
  200. (void) fprintf(stdout, "--DIAG: "
  201. "scf_tmpl_get_by_pg_name() returned an error\n"
  202. "\tERROR: %u (%s)\n",
  203. (unsigned int)scf_err, scf_strerror(scf_err));
  204. *exp_err = FAIL;
  205. } else {
  206. *exp_err = PASS;
  207. }
  208. return (scf_ret);
  209. }
  210. /*
  211. * scftest_tmpl_get_by_prop
  212. * Purpose: Call scf_tmpl_get_by_prop()
  213. * Parameters:
  214. * input: scf_handle_t *h; a handle
  215. * const char *fmri: an instance
  216. * const char *snapshot: a snapshot name
  217. * const char *pg: a property group
  218. * int flags: scf_tmpl_get_by_prop flags
  219. * scf_error_t *exp_err: the expected scf error code
  220. * output: none
  221. * Returns: The result of the scf_tmpl_get_by_prop call with PASS
  222. * or FAIL in the exp_err pointer.
  223. */
  224. int
  225. scftest_tmpl_get_by_prop(scf_pg_tmpl_t *t, const char *prop,
  226. scf_prop_tmpl_t *property, int flags, scf_error_t *exp_err) {
  227. scf_error_t scf_err = SCF_ERROR_NONE;
  228. int scf_ret;
  229. if (*exp_err != SCF_ERROR_NONE) {
  230. (void) fprintf(stdout, "--INFO: "
  231. "Call scf_tmpl_get_by_prop() and expect an error\n");
  232. } else {
  233. (void) fprintf(stdout, "--INFO: "
  234. "Call scf_tmpl_get_by_prop() and return the prop "
  235. "template\n");
  236. }
  237. scf_ret = scf_tmpl_get_by_prop(t, prop, property, flags);
  238. scf_err = scf_error();
  239. if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
  240. /*
  241. * An error was expected check that the error returned
  242. * matches the expected error and report anomalies as
  243. * well as success.
  244. */
  245. if (scf_err != *exp_err) {
  246. (void) fprintf(stdout, "--DIAG: "
  247. "scf_tmpl_get_by_prop() returned the wrong "
  248. "error\n\t"
  249. "EXPECTED: %u (%s)\n\t"
  250. "RETURNED: %u (%s)\n",
  251. (unsigned int)*exp_err, scf_strerror(*exp_err),
  252. (unsigned int)scf_err, scf_strerror(scf_err));
  253. *exp_err = FAIL;
  254. } else {
  255. (void) fprintf(stdout, "--INFO: "
  256. "scf_tmpl_get_by_prop() failed as expected\n");
  257. *exp_err = PASS;
  258. }
  259. } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
  260. /*
  261. * An error was expected but the template came back as
  262. * non-null which it should not have, therefore report
  263. * the anomaly.
  264. */
  265. (void) fprintf(stdout, "--DIAG: "
  266. "scf_tmpl_get_by_prop() did not fail as expected\n\t"
  267. "RETURNED: 0x%p\n", (void *)property);
  268. /* scf_prop_tmpl_free(template); */
  269. property = NULL;
  270. *exp_err = FAIL;
  271. } else if (scf_ret == -1) {
  272. /*
  273. * No error was expected, and template is still NULL
  274. * report the anomaly.
  275. */
  276. (void) fprintf(stdout, "--DIAG: "
  277. "scf_tmpl_get_by_prop() returned an error\n\t"
  278. "ERROR: %u (%s)\n",
  279. (unsigned int)scf_err, scf_strerror(scf_err));
  280. *exp_err = FAIL;
  281. } else {
  282. *exp_err = PASS;
  283. }
  284. return (scf_ret);
  285. }
  286. /*
  287. * scftest_tmpl_iter_pgs
  288. * Purpose: Call scf_tmpl_iter_pgs()
  289. * Parameters:
  290. * input: scf_pg_tmpl_t *t: current template pointer
  291. * const char *fmri: an instance
  292. * const char *snapshot: a snapshot name
  293. * const char *pg: a property group
  294. * int flags: scf_tmpl_iter_pgs flags
  295. * scf_error_t *exp_err: the expected scf error code
  296. * output: none
  297. * Returns: The result of the scf_tmpl_iter_pgs call with PASS
  298. * or FAIL in the exp_err pointer.
  299. */
  300. int
  301. scftest_tmpl_iter_pgs(scf_pg_tmpl_t *t, const char *fmri,
  302. const char *snapshot, const char *pg_type, int flags,
  303. scf_error_t *exp_err) {
  304. scf_error_t scf_err = SCF_ERROR_NONE;
  305. int scf_ret;
  306. if (*exp_err != SCF_ERROR_NONE) {
  307. (void) fprintf(stdout, "--INFO: "
  308. "Call scf_tmpl_iter_pgs() and expect an error\n");
  309. } else {
  310. (void) fprintf(stdout, "--INFO: "
  311. "Call scf_tmpl_iter_pgs() and return the pg template\n");
  312. }
  313. scf_ret = scf_tmpl_iter_pgs(t, fmri, snapshot, pg_type, flags);
  314. scf_err = scf_error();
  315. if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
  316. /*
  317. * An error was expected check that the error returned
  318. * matches the expected error and report anomalies as
  319. * well as success.
  320. */
  321. if (scf_err != *exp_err) {
  322. (void) fprintf(stdout, "--DIAG: "
  323. "scf_tmpl_iter_pgs() returned the wrong error\n\t"
  324. "EXPECTED: %u (%s)\n\t"
  325. "RETURNED: %u (%s)\n",
  326. (unsigned int)*exp_err, scf_strerror(*exp_err),
  327. (unsigned int)scf_err, scf_strerror(scf_err));
  328. *exp_err = FAIL;
  329. } else {
  330. (void) fprintf(stdout, "--INFO: "
  331. "scf_tmpl_iter_pgs() failed as expected\n");
  332. *exp_err = PASS;
  333. }
  334. } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
  335. /*
  336. * An error was expected but the template came back as
  337. * non-null which it should not have, therefore report
  338. * the anomaly.
  339. */
  340. (void) fprintf(stdout, "--DIAG: "
  341. "scf_tmpl_iter_pgs() did not fail as expected\n\t"
  342. "and returned a template\n\t"
  343. "RETURNED: %d\n", scf_ret);
  344. *exp_err = FAIL;
  345. } else if (scf_ret == -1) {
  346. /*
  347. * No error was expected, and template is still NULL
  348. * report the anomaly.
  349. */
  350. (void) fprintf(stdout, "--INFO: "
  351. "scf_tmpl_iter_pgs() returned an error, "
  352. "the end of property groups, %s\n",
  353. scf_strerror(scf_err));
  354. *exp_err = FAIL;
  355. } else {
  356. *exp_err = PASS;
  357. }
  358. return (scf_ret);
  359. }
  360. /*
  361. * scftest_tmpl_iter_props
  362. * Purpose: Call scf_tmpl_iter_props()
  363. * Parameters:
  364. * input: scf_pg_tmpl_t *t: current template pointer
  365. * scf_handle_t *h: a handle
  366. * const char *fmri: an instance
  367. * const char *snapshot: a snapshot name
  368. * const char *pg: a property group
  369. * int flags: scf_tmpl_iter_props flags
  370. * scf_error_t *exp_err: the expected scf error code
  371. * output: none
  372. * Returns: The result of the scf_tmpl_iter_props call with PASS
  373. * or FAIL in the exp_err pointer.
  374. */
  375. int
  376. scftest_tmpl_iter_props(scf_pg_tmpl_t *t, scf_prop_tmpl_t *p, int flags,
  377. scf_error_t *exp_err) {
  378. scf_error_t scf_err = SCF_ERROR_NONE;
  379. int scf_ret;
  380. if (*exp_err != SCF_ERROR_NONE) {
  381. (void) fprintf(stdout, "--INFO: "
  382. "Call scf_tmpl_iter_props() and expect an error\n");
  383. } else {
  384. (void) fprintf(stdout, "--INFO: Call scf_tmpl_iter_props() "
  385. "and return the prop template\n");
  386. }
  387. scf_ret = scf_tmpl_iter_props(t, p, flags);
  388. scf_err = scf_error();
  389. if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
  390. /*
  391. * An error was expected check that the error returned
  392. * matches the expected error and report anomalies as
  393. * well as success.
  394. */
  395. if (scf_err != *exp_err) {
  396. (void) fprintf(stdout, "--DIAG: "
  397. "scf_tmpl_iter_pgs() returned the wrong error\n\t"
  398. "EXPECTED: %u (%s)\n\t"
  399. "RETURNED: %u (%s)\n",
  400. (unsigned int)*exp_err, scf_strerror(*exp_err),
  401. (unsigned int)scf_err, scf_strerror(scf_err));
  402. *exp_err = FAIL;
  403. } else {
  404. (void) fprintf(stdout, "--INFO: "
  405. "scf_tmpl_iter_pgs() failed as expected\n");
  406. *exp_err = PASS;
  407. }
  408. } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
  409. /*
  410. * An error was expected but the template came back as
  411. * non-null which it should not have, therefore report
  412. * the anomaly.
  413. */
  414. (void) fprintf(stdout, "--DIAG: "
  415. "scf_tmpl_iter_pgs() did not fail as expected\n\t"
  416. "and returned a prop\n\t"
  417. "RETURNED: %d\n", scf_ret);
  418. *exp_err = FAIL;
  419. } else if (scf_ret == -1) {
  420. /*
  421. * No error was expected, and template is still NULL
  422. * report the anomaly.
  423. */
  424. (void) fprintf(stdout, "--INFO: "
  425. "scf_tmpl_iter_pgs() returned an error, "
  426. "the end of property groups %s\n",
  427. scf_strerror(scf_err));
  428. *exp_err = FAIL;
  429. } else {
  430. *exp_err = PASS;
  431. }
  432. return (scf_ret);
  433. }
  434. /*
  435. * scftest_tmpl_pg_name
  436. * Purpose: Call scf_tmpl_pg_name()
  437. * Parameters:
  438. * input: scf_pg_tmpl_t *t; a template
  439. * char **name: a pointer to the pointer for the name
  440. * scf_error_t *exp_err: the expected error
  441. * output: none
  442. * Returns: The result of the scf_tmpl_pg_name call with PASS
  443. * or FAIL in the exp_err pointer.
  444. */
  445. ssize_t
  446. scftest_tmpl_pg_name(scf_pg_tmpl_t *t, char **name, scf_error_t *exp_err) {
  447. scf_error_t scf_err = SCF_ERROR_NONE;
  448. ssize_t scf_ret;
  449. if (*exp_err != SCF_ERROR_NONE) {
  450. (void) fprintf(stdout, "--INFO: "
  451. "Call scf_tmpl_pg_name() and expect an error\n");
  452. } else {
  453. (void) fprintf(stdout, "--INFO: "
  454. "Call scf_tmpl_pg_name() and return the pg name\n");
  455. }
  456. scf_ret = scf_tmpl_pg_name(t, name);
  457. scf_err = scf_error();
  458. if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
  459. /*
  460. * An error was expected check that the error returned
  461. * matches the expected error and report anomalies as
  462. * well as success.
  463. */
  464. if (scf_err != *exp_err) {
  465. (void) fprintf(stdout, "--DIAG: "
  466. "scf_tmpl_pg_name() returned the wrong error\n\t"
  467. "EXPECTED: %d \n\t"
  468. "RETURNED: %d \n",
  469. (unsigned int)*exp_err, scf_ret);
  470. *exp_err = FAIL;
  471. } else {
  472. (void) fprintf(stdout, "--INFO: "
  473. "scf_tmpl_pg_name() failed as expected\n");
  474. *exp_err = PASS;
  475. }
  476. } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
  477. /*
  478. * An error was expected but the template came back as
  479. * non-null which it should not have, therefore report
  480. * the anomaly.
  481. */
  482. (void) fprintf(stdout, "--DIAG: "
  483. "scf_tmpl_pg_name() did not fail as expected\n\t"
  484. "RETURNED: 0x%p\n", (void *)*name);
  485. if (*name)
  486. free(*name);
  487. *exp_err = FAIL;
  488. } else if (scf_ret == -1) {
  489. /*
  490. * No error was expected, and template is still NULL
  491. * report the anomaly.
  492. */
  493. (void) fprintf(stdout, "--DIAG: "
  494. "scf_tmpl_pg_name() returned an error\n\t"
  495. "ERROR: %u (%s)\n",
  496. (unsigned int)scf_err, scf_strerror(scf_err));
  497. *exp_err = FAIL;
  498. } else if (*name == NULL) {
  499. (void) fprintf(stdout, "--DIAG: "
  500. "scf_tmpl_pg_name() did not fill in the cname pointer");
  501. *exp_err = FAIL;
  502. } else {
  503. *exp_err = PASS;
  504. }
  505. return (scf_ret);
  506. }
  507. /*
  508. * scftest_tmpl_pg_common_name
  509. * Purpose: Call scf_tmpl_pg_common_name()
  510. * Parameters:
  511. * input: scf_pg_tmpl_t *t; a template
  512. * char **cname: a pointer to the pointer for the common name
  513. * scf_error_t *exp_err: the expected error
  514. * output: none
  515. * Returns: The result of the scf_tmpl_pg_common_name call with PASS
  516. * or FAIL in the exp_err pointer.
  517. */
  518. ssize_t
  519. scftest_tmpl_pg_common_name(scf_pg_tmpl_t *t, const char *locale, char **cname,
  520. scf_error_t *exp_err) {
  521. scf_error_t scf_err = SCF_ERROR_NONE;
  522. ssize_t scf_ret;
  523. if (*exp_err != SCF_ERROR_NONE) {
  524. (void) fprintf(stdout, "--INFO: "
  525. "Call scf_tmpl_pg_common_name() and expect an error\n");
  526. } else {
  527. (void) fprintf(stdout, "--INFO: "
  528. "Call scf_tmpl_pg_common_name() and "
  529. "return the pg template\n");
  530. }
  531. scf_ret = scf_tmpl_pg_common_name(t, locale, cname);
  532. scf_err = scf_error();
  533. if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
  534. /*
  535. * An error was expected check that the error returned
  536. * matches the expected error and report anomalies as
  537. * well as success.
  538. */
  539. if (scf_err != *exp_err) {
  540. (void) fprintf(stdout, "--DIAG: "
  541. "scf_tmpl_pg_common_name() "
  542. "returned the wrong error\n\t"
  543. "EXPECTED: %d \n\t"
  544. "RETURNED: %d \n",
  545. (unsigned int)*exp_err, scf_ret);
  546. *exp_err = FAIL;
  547. } else {
  548. (void) fprintf(stdout, "--INFO: "
  549. "scf_tmpl_pg_common_name() failed as expected\n");
  550. *exp_err = PASS;
  551. }
  552. } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
  553. /*
  554. * An error was expected but the template came back as
  555. * non-null which it should not have, therefore report
  556. * the anomaly.
  557. */
  558. (void) fprintf(stdout, "--DIAG: "
  559. "scf_tmpl_pg_common_name() did not fail as expected\n\t"
  560. "RETURNED: 0x%p\n", (void *)*cname);
  561. if (*cname)
  562. free(*cname);
  563. *exp_err = FAIL;
  564. } else if (scf_ret == -1) {
  565. /*
  566. * No error was expected, and template is still NULL
  567. * report the anomaly.
  568. */
  569. (void) fprintf(stdout, "--DIAG: "
  570. "scf_tmpl_pg_common_name() returned an error\n\t"
  571. "ERROR: %u (%s)\n",
  572. (unsigned int)scf_err, scf_strerror(scf_err));
  573. *exp_err = FAIL;
  574. } else if (*cname == NULL) {
  575. (void) fprintf(stdout, "--DIAG: "
  576. "scf_tmpl_pg_common_name() did not "
  577. "fill in the cname pointer");
  578. *exp_err = FAIL;
  579. } else {
  580. *exp_err = PASS;
  581. }
  582. return (scf_ret);
  583. }
  584. /*
  585. * scftest_tmpl_pg_description
  586. * Purpose: Call scf_tmpl_pg_description()
  587. * Parameters:
  588. * input: scf_pg_tmpl_t *t; a template
  589. * char **description: a pointer to the pointer for the description
  590. * scf_error_t *exp_err: the expected error
  591. * output: none
  592. * Returns: The result of the scf_tmpl_pg_description call with PASS
  593. * or FAIL in the exp_err pointer.
  594. */
  595. ssize_t
  596. scftest_tmpl_pg_description(scf_pg_tmpl_t *t, const char *locale,
  597. char **description, scf_error_t *exp_err) {
  598. scf_error_t scf_err = SCF_ERROR_NONE;
  599. ssize_t scf_ret;
  600. if (*exp_err != SCF_ERROR_NONE) {
  601. (void) fprintf(stdout, "--INFO: "
  602. "Call scf_tmpl_pg_description() and expect an error\n");
  603. } else {
  604. (void) fprintf(stdout, "--INFO: "
  605. "Call scf_tmpl_pg_description() and "
  606. "return the pg template\n");
  607. }
  608. scf_ret = scf_tmpl_pg_description(t, locale, description);
  609. scf_err = scf_error();
  610. if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
  611. /*
  612. * An error was expected check that the error returned
  613. * matches the expected error and report anomalies as
  614. * well as success.
  615. */
  616. if (scf_err != *exp_err) {
  617. (void) fprintf(stdout, "--DIAG: "
  618. "scf_tmpl_pg_description() "
  619. "returned the wrong error\n\t"
  620. "EXPECTED: %d \n\t"
  621. "RETURNED: %d \n",
  622. (unsigned int)*exp_err, scf_ret);
  623. *exp_err = FAIL;
  624. } else {
  625. (void) fprintf(stdout, "--INFO: "
  626. "scf_tmpl_pg_description() failed as expected\n");
  627. *exp_err = PASS;
  628. }
  629. } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
  630. /*
  631. * An error was expected but the template came back as
  632. * non-null which it should not have, therefore report
  633. * the anomaly.
  634. */
  635. (void) fprintf(stdout, "--DIAG: "
  636. "scf_tmpl_pg_description() did not fail as expected\n\t"
  637. "RETURNED: 0x%p\n", (void *)*description);
  638. if (*description)
  639. free(*description);
  640. *exp_err = FAIL;
  641. } else if (scf_ret == -1) {
  642. /*
  643. * No error was expected, and template is still NULL
  644. * report the anomaly.
  645. */
  646. (void) fprintf(stdout, "--DIAG: "
  647. "scf_tmpl_pg_description() returned an error\n\t"
  648. "ERROR: %u (%s)\n",
  649. (unsigned int)scf_err, scf_strerror(scf_err));
  650. *exp_err = FAIL;
  651. } else if (*description == NULL) {
  652. (void) fprintf(stdout, "--DIAG: "
  653. "scf_tmpl_pg_description() did not "
  654. "fill in the description pointer");
  655. *exp_err = FAIL;
  656. } else {
  657. *exp_err = PASS;
  658. }
  659. return (scf_ret);
  660. }
  661. /*
  662. * scftest_tmpl_pg_type
  663. * Purpose: Call scf_tmpl_pg_type()
  664. * Parameters:
  665. * input: scf_pg_tmpl_t *t; a template
  666. * char **type: a pointer to the pointer for the type
  667. * scf_error_t *exp_err: the expected error
  668. * output: none
  669. * Returns: The result of the scf_tmpl_pg_type call with PASS
  670. * or FAIL in the exp_err pointer.
  671. */
  672. ssize_t
  673. scftest_tmpl_pg_type(scf_pg_tmpl_t *t, char **type, scf_error_t *exp_err) {
  674. scf_error_t scf_err = SCF_ERROR_NONE;
  675. ssize_t scf_ret;
  676. if (*exp_err != SCF_ERROR_NONE) {
  677. (void) fprintf(stdout, "--INFO: "
  678. "Call scf_tmpl_pg_type() and expect an error\n");
  679. } else {
  680. (void) fprintf(stdout, "--INFO: "
  681. "Call scf_tmpl_pg_type() and return the pg template\n");
  682. }
  683. scf_ret = scf_tmpl_pg_type(t, type);
  684. scf_err = scf_error();
  685. if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
  686. /*
  687. * An error was expected check that the error returned
  688. * matches the expected error and report anomalies as
  689. * well as success.
  690. */
  691. if (scf_ret != *exp_err) {
  692. (void) fprintf(stdout, "--DIAG: "
  693. "scf_tmpl_pg_type() returned the wrong error\n\t"
  694. "EXPECTED: %d \n\t"
  695. "RETURNED: %d \n",
  696. (unsigned int)*exp_err, scf_ret);
  697. *exp_err = FAIL;
  698. } else {
  699. (void) fprintf(stdout, "--INFO: "
  700. "scf_tmpl_pg_type() failed as expected\n");
  701. *exp_err = PASS;
  702. }
  703. } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
  704. /*
  705. * An error was expected but the template came back as
  706. * non-null which it should not have, therefore report
  707. * the anomaly.
  708. */
  709. (void) fprintf(stdout, "--DIAG: "
  710. "scf_tmpl_pg_type() did not fail as expected\n\t"
  711. "RETURNED: 0x%p\n", (void *)*type);
  712. if (*type)
  713. free(*type);
  714. *exp_err = FAIL;
  715. } else if (scf_ret == -1) {
  716. /*
  717. * No error was expected, and template is still NULL
  718. * report the anomaly.
  719. */
  720. (void) fprintf(stdout, "--DIAG: "
  721. "scf_tmpl_pg_type() returned an error\n\t"
  722. "ERROR: %u (%s)\n",
  723. (unsigned int)scf_err, scf_strerror(scf_err));
  724. *exp_err = FAIL;
  725. } else if (*type == NULL) {
  726. (void) fprintf(stdout, "--DIAG: "
  727. "scf_tmpl_pg_type() did not fill in the type pointer");
  728. *exp_err = FAIL;
  729. } else {
  730. *exp_err = PASS;
  731. }
  732. return (scf_ret);
  733. }
  734. /*
  735. * scftest_tmpl_pg_required
  736. * Purpose: Call scf_tmpl_pg_required()
  737. * Parameters:
  738. * input: scf_pg_tmpl_t *t; a template
  739. * uint8_t *required: a pointer to the required flag
  740. * scf_error_t *exp_err: the expected error
  741. * output: none
  742. * Returns: The result of the scf_tmpl_pg_required call with PASS
  743. * or FAIL in the exp_err pointer.
  744. */
  745. int
  746. scftest_tmpl_pg_required(scf_pg_tmpl_t *t, uint8_t *required,
  747. scf_error_t *exp_err) {
  748. scf_error_t scf_err = SCF_ERROR_NONE;
  749. int scf_ret;
  750. if (*exp_err != SCF_ERROR_NONE) {
  751. (void) fprintf(stdout, "--INFO: "
  752. "Call scf_tmpl_pg_required() and expect an error\n");
  753. } else {
  754. (void) fprintf(stdout, "--INFO: "
  755. "Call scf_tmpl_pg_required() and return the pg template\n");
  756. }
  757. scf_ret = scf_tmpl_pg_required(t, required);
  758. scf_err = scf_error();
  759. if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
  760. /*
  761. * An error was expected check that the error returned
  762. * matches the expected error and report anomalies as
  763. * well as success.
  764. */
  765. if (scf_err != *exp_err) {
  766. (void) fprintf(stdout, "--DIAG: "
  767. "scf_tmpl_pg_required() "
  768. "returned the wrong error\n"
  769. "\tEXPECTED: %d \n"
  770. "\tRETURNED: %d \n"
  771. "\tSCF_ERROR: %s\n",
  772. (unsigned int)*exp_err, scf_err,
  773. scf_strerror(scf_error()));
  774. *exp_err = FAIL;
  775. } else {
  776. *exp_err = PASS;
  777. (void) fprintf(stdout, "--INFO: "
  778. "scf_tmpl_pg_required() failed as expected\n");
  779. }
  780. } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
  781. /*
  782. * An error was expected but the template came back as
  783. * non-null which it should not have, therefore report
  784. * the anomaly.
  785. */
  786. (void) fprintf(stdout, "--DIAG: "
  787. "scf_tmpl_pg_required() did not fail as expected\n"
  788. "\tRETURNED : %d\n"
  789. "\trequired : %hu\n", scf_ret, (uint8_t)required);
  790. *exp_err = FAIL;
  791. } else if (scf_ret == -1) {
  792. /*
  793. * No error was expected, and template is still NULL
  794. * report the anomaly.
  795. */
  796. (void) fprintf(stdout, "--DIAG: "
  797. "scf_tmpl_pg_required() returned an error\n\t"
  798. "ERROR: %u (%s)\n",
  799. (unsigned int)scf_err, scf_strerror(scf_err));
  800. *exp_err = FAIL;
  801. } else {
  802. *exp_err = PASS;
  803. }
  804. return (scf_ret);
  805. }
  806. /*
  807. * scftest_tmpl_prop_name
  808. * Purpose: Call scf_tmpl_prop_name()
  809. * Parameters:
  810. * input: scf_prop_tmpl_t *t: a template property
  811. * char **name: a pointer to the pointer for the name
  812. * scf_error_t *exp_err: the expected error
  813. * output: none
  814. * Returns: The result of the scf_tmpl_prop_name call with PASS
  815. * or FAIL in the exp_err pointer.
  816. */
  817. int
  818. scftest_tmpl_prop_name(scf_prop_tmpl_t *p, char **name, scf_error_t *exp_err) {
  819. scf_error_t scf_err = SCF_ERROR_NONE;
  820. int scf_ret;
  821. if (*exp_err != SCF_ERROR_NONE) {
  822. (void) fprintf(stdout, "--INFO: "
  823. "Call scf_tmpl_prop_name() and expect an error\n");
  824. } else {
  825. (void) fprintf(stdout, "--INFO: "
  826. "Call scf_tmpl_prop_name() and return the property name\n");
  827. }
  828. scf_ret = scf_tmpl_prop_name(p, name);
  829. scf_err = scf_error();
  830. if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
  831. /*
  832. * An error was expected check that the error returned
  833. * matches the expected error and report anomalies as
  834. * well as success.
  835. */
  836. if (scf_err != *exp_err) {
  837. (void) fprintf(stdout, "--DIAG: "
  838. "scf_tmpl_prop_name() returned the wrong error\n\t"
  839. "EXPECTED: %d \n\t"
  840. "RETURNED: %d \n",
  841. (unsigned int)*exp_err, scf_ret);
  842. *exp_err = FAIL;
  843. } else {
  844. (void) fprintf(stdout, "--INFO: "
  845. "scf_tmpl_prop_name() failed as expected\n");
  846. *exp_err = PASS;
  847. }
  848. } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
  849. /*
  850. * An error was expected but the template came back as
  851. * non-null which it should not have, therefore report
  852. * the anomaly.
  853. */
  854. (void) fprintf(stdout, "--DIAG: "
  855. "scf_tmpl_prop_name() did not fail as expected\n\t"
  856. "RETURNED: 0x%p\n", (void *)*name);
  857. if (*name)
  858. free(*name);
  859. *exp_err = FAIL;
  860. } else if (scf_ret == -1) {
  861. /*
  862. * No error was expected, and template is still NULL
  863. * report the anomaly.
  864. */
  865. (void) fprintf(stdout, "--DIAG: "
  866. "scf_tmpl_prop_name() returned an error\n\t"
  867. "ERROR: %u (%s)\n",
  868. (unsigned int)scf_err, scf_strerror(scf_err));
  869. *exp_err = FAIL;
  870. } else if (*name == NULL) {
  871. (void) fprintf(stdout, "--DIAG: "
  872. "scf_tmpl_prop_name() did not fill in the name pointer");
  873. *exp_err = FAIL;
  874. } else {
  875. *exp_err = PASS;
  876. }
  877. return (scf_ret);
  878. }
  879. /*
  880. * scftest_tmpl_prop_type
  881. * Purpose: Call scf_tmpl_prop_type()
  882. * Parameters:
  883. * input: scf_pg_tmpl_t *p; a property
  884. * scf_type_t *type: a pointer to the pointer for the type
  885. * scf_error_t *exp_err: the expected error
  886. * output: none
  887. * Returns: The result of the scf_tmpl_prop_type call with PASS
  888. * or FAIL in the exp_err pointer.
  889. */
  890. int
  891. scftest_tmpl_prop_type(scf_prop_tmpl_t *p, scf_type_t *type,
  892. scf_error_t *exp_err) {
  893. scf_error_t scf_err = SCF_ERROR_NONE;
  894. int scf_ret;
  895. if (*exp_err != SCF_ERROR_NONE) {
  896. (void) fprintf(stdout, "--INFO: "
  897. "Call scf_tmpl_prop_type() and expect an error\n");
  898. } else {
  899. (void) fprintf(stdout, "--INFO: "
  900. "Call scf_tmpl_prop_type() and return the propety type\n");
  901. }
  902. scf_ret = scf_tmpl_prop_type(p, type);
  903. scf_err = scf_error();
  904. if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
  905. /*
  906. * An error was expected check that the error returned
  907. * matches the expected error and report anomalies as
  908. * well as success.
  909. */
  910. if (scf_err != *exp_err) {
  911. (void) fprintf(stdout, "--DIAG: "
  912. "scf_tmpl_prop_type() returned the wrong error\n\t"
  913. "EXPECTED: %d \n\t"
  914. "RETURNED: %d \n",
  915. (unsigned int)*exp_err, scf_ret);
  916. *exp_err = FAIL;
  917. } else {
  918. (void) fprintf(stdout, "--INFO: "
  919. "scf_tmpl_prop_type() failed as expected\n");
  920. *exp_err = PASS;
  921. }
  922. } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
  923. /*
  924. * An error was expected but the template came back as
  925. * non-null which it should not have, therefore report
  926. * the anomaly.
  927. */
  928. (void) fprintf(stdout, "--DIAG: "
  929. "scf_tmpl_prop_type() did not fail as expected\n\t"
  930. "RETURNED: 0x%p\n", (void *)*type);
  931. *exp_err = FAIL;
  932. } else if (scf_ret == -1) {
  933. /*
  934. * No error was expected, and template is still NULL
  935. * report the anomaly.
  936. */
  937. (void) fprintf(stdout, "--DIAG: "
  938. "scf_tmpl_prop_type() returned an error\n\t"
  939. "ERROR: %u (%s)\n",
  940. (unsigned int)scf_err, scf_strerror(scf_err));
  941. *exp_err = FAIL;
  942. } else if (*type == NULL) {
  943. (void) fprintf(stdout, "--DIAG: "
  944. "scf_tmpl_prop_type() did not fill in the type pointer");
  945. *exp_err = FAIL;
  946. } else {
  947. *exp_err = PASS;
  948. }
  949. return (scf_ret);
  950. }
  951. /*
  952. * scftest_tmpl_prop_required
  953. * Purpose: Call scf_tmpl_prop_required()
  954. * Parameters:
  955. * input: scf_prop_tmpl_t *p: a property
  956. * uint8_t *required: a pointer to the required flag
  957. * scf_error_t *exp_err: the expected error
  958. * output: none
  959. * Returns: The result of the scf_tmpl_prop_required call with PASS
  960. * or FAIL in the exp_err pointer.
  961. */
  962. int
  963. scftest_tmpl_prop_required(scf_prop_tmpl_t *p, uint8_t *required,
  964. scf_error_t *exp_err) {
  965. scf_error_t scf_err = SCF_ERROR_NONE;
  966. int scf_ret;
  967. if (*exp_err != SCF_ERROR_NONE) {
  968. (void) fprintf(stdout, "--INFO: "
  969. "Call scf_tmpl_prop_required() and expect an error\n");
  970. } else {
  971. (void) fprintf(stdout, "--INFO: "
  972. "Call scf_tmpl_prop_required() and "
  973. "return the required flag\n");
  974. }
  975. scf_ret = scf_tmpl_prop_required(p, required);
  976. scf_err = scf_error();
  977. if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
  978. /*
  979. * An error was expected check that the error returned
  980. * matches the expected error and report anomalies as
  981. * well as success.
  982. */
  983. if (scf_err != *exp_err) {
  984. (void) fprintf(stdout, "--DIAG: "
  985. "scf_tmpl_prop_required() "
  986. "returned the wrong error\n\t"
  987. "EXPECTED: %d \n\t"
  988. "RETURNED: %d \n",
  989. (unsigned int)*exp_err, scf_ret);
  990. *exp_err = FAIL;
  991. } else {
  992. (void) fprintf(stdout, "--INFO: "
  993. "scf_tmpl_prop_required() failed as expected\n");
  994. *exp_err = PASS;
  995. }
  996. } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
  997. /*
  998. * An error was expected but the template came back as
  999. * non-null which it should not have, therefore report
  1000. * the anomaly.
  1001. */
  1002. (void) fprintf(stdout, "--DIAG: "
  1003. "scf_tmpl_prop_required() did not fail as expected\n\t"
  1004. "RETURNED: %u\n", (uint8_t)required);
  1005. *exp_err = FAIL;
  1006. } else if (scf_ret == -1) {
  1007. /*
  1008. * No error was expected, and template is still NULL
  1009. * report the anomaly.
  1010. */
  1011. (void) fprintf(stdout, "--DIAG: "
  1012. "scf_tmpl_prop_required() returned an error\n\t"
  1013. "ERROR: %u (%s)\n",
  1014. (unsigned int)scf_err, scf_strerror(scf_err));
  1015. *exp_err = FAIL;
  1016. } else {
  1017. *exp_err = PASS;
  1018. }
  1019. return (scf_ret);
  1020. }
  1021. /*
  1022. * scftest_tmpl_prop_common_name
  1023. * Purpose: Call scf_tmpl_prop_common_name()
  1024. * Parameters:
  1025. * input: scf_prop_tmpl_t *p: a property
  1026. * char **cname: a pointer to the pointer for the common name
  1027. * scf_error_t *exp_err: the expected error
  1028. * output: none
  1029. * Returns: The result of the scf_tmpl_prop_common_name call with PASS
  1030. * or FAIL in the exp_err pointer.
  1031. */
  1032. ssize_t
  1033. scftest_tmpl_prop_common_name(scf_prop_tmpl_t *p, const char *locale,
  1034. char **cname, scf_error_t *exp_err) {
  1035. scf_error_t scf_err = SCF_ERROR_NONE;
  1036. int scf_ret;
  1037. if (*exp_err != SCF_ERROR_NONE) {
  1038. (void) fprintf(stdout, "--INFO: "
  1039. "Call scf_tmpl_prop_common_name() and "
  1040. "expect an error\n");
  1041. } else {
  1042. (void) fprintf(stdout, "--INFO: "
  1043. "Call scf_tmpl_prop_common_name() and "
  1044. "return the pg template\n");
  1045. }
  1046. scf_ret = scf_tmpl_prop_common_name(p, locale, cname);
  1047. scf_err = scf_error();
  1048. if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
  1049. /*
  1050. * An error was expected check that the error returned
  1051. * matches the expected error and report anomalies as
  1052. * well as success.
  1053. */
  1054. if (scf_err != *exp_err) {
  1055. (void) fprintf(stdout, "--DIAG: "
  1056. "scf_tmpl_prop_common_name() "
  1057. "returned the wrong error\n\t"
  1058. "EXPECTED: %d \n\t"
  1059. "RETURNED: %d \n",
  1060. (unsigned int)*exp_err, scf_ret);
  1061. *exp_err = FAIL;
  1062. } else {
  1063. (void) fprintf(stdout, "--INFO: "
  1064. "scf_tmpl_prop_common_name() failed as expected\n");
  1065. *exp_err = PASS;
  1066. }
  1067. } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
  1068. /*
  1069. * An error was expected but the template came back as
  1070. * non-null which it should not have, therefore report
  1071. * the anomaly.
  1072. */
  1073. (void) fprintf(stdout, "--DIAG: "
  1074. "scf_tmpl_prop_common_name() did not fail as expected\n\t"
  1075. "RETURNED: 0x%p\n", (void *)*cname);
  1076. if (*cname)
  1077. free(*cname);
  1078. *exp_err = FAIL;
  1079. } else if (scf_ret == -1) {
  1080. /*
  1081. * No error was expected, and template is still NULL
  1082. * report the anomaly.
  1083. */
  1084. (void) fprintf(stdout, "--DIAG: "
  1085. "scf_tmpl_prop_common_name() returned an error\n\t"
  1086. "ERROR: %u (%s)\n",
  1087. (unsigned int)scf_err, scf_strerror(scf_err));
  1088. *exp_err = FAIL;
  1089. } else if (*cname == NULL) {
  1090. (void) fprintf(stdout, "--DIAG: "
  1091. "scf_tmpl_prop_common_name() did not "
  1092. "fill in the cname pointer");
  1093. *exp_err = FAIL;
  1094. } else {
  1095. *exp_err = PASS;
  1096. }
  1097. return (scf_ret);
  1098. }
  1099. /*
  1100. * scftest_tmpl_prop_description
  1101. * Purpose: Call scf_tmpl_prop_description()
  1102. * Parameters:
  1103. * input: scf_prop_tmpl_t *p: a property
  1104. * char **description: a pointer to the pointer for the description
  1105. * scf_error_t *exp_err: the expected error
  1106. * output: none
  1107. * Returns: The result of the scf_tmpl_prop_description call with PASS
  1108. * or FAIL in the exp_err pointer.
  1109. */
  1110. ssize_t
  1111. scftest_tmpl_prop_description(scf_prop_tmpl_t *p, const char *locale,
  1112. char **description, scf_error_t *exp_err) {
  1113. scf_error_t scf_err = SCF_ERROR_NONE;
  1114. int scf_ret;
  1115. if (*exp_err != SCF_ERROR_NONE) {
  1116. (void) fprintf(stdout, "--INFO: "
  1117. "Call scf_tmpl_prop_description() and "
  1118. "expect an error\n");
  1119. } else {
  1120. (void) fprintf(stdout, "--INFO: "
  1121. "Call scf_tmpl_prop_description() and "
  1122. "return the pg template\n");
  1123. }
  1124. scf_ret = scf_tmpl_prop_description(p, locale, description);
  1125. scf_err = scf_error();
  1126. if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
  1127. /*
  1128. * An error was expected check that the error returned
  1129. * matches the expected error and report anomalies as
  1130. * well as success.
  1131. */
  1132. if (scf_err != *exp_err) {
  1133. (void) fprintf(stdout, "--DIAG: "
  1134. "scf_tmpl_prop_description() "
  1135. "returned the wrong error\n\t"
  1136. "EXPECTED: %d \n\t"
  1137. "RETURNED: %d \n",
  1138. (unsigned int)*exp_err, scf_err);
  1139. *exp_err = FAIL;
  1140. } else {
  1141. (void) fprintf(stdout, "--INFO: "
  1142. "scf_tmpl_prop_description() failed as expected\n");
  1143. *exp_err = PASS;
  1144. }
  1145. } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
  1146. /*
  1147. * An error was expected but the template came back as
  1148. * non-null which it should not have, therefore report
  1149. * the anomaly.
  1150. */
  1151. (void) fprintf(stdout, "--DIAG: "
  1152. "scf_tmpl_prop_description() did not fail as expected\n\t"
  1153. "RETURNED: 0x%p\n", (void *)*description);
  1154. if (*description)
  1155. free(*description);
  1156. *exp_err = FAIL;
  1157. } else if (scf_ret == -1) {
  1158. /*
  1159. * No error was expected, and template is still NULL
  1160. * report the anomaly.
  1161. */
  1162. (void) fprintf(stdout, "--DIAG: "
  1163. "scf_tmpl_prop_description() returned an error\n\t"
  1164. "ERROR: %u (%s)\n",
  1165. (unsigned int)scf_err, scf_strerror(scf_err));
  1166. *exp_err = FAIL;
  1167. } else if (*description == NULL) {
  1168. (void) fprintf(stdout, "--DIAG: "
  1169. "scf_tmpl_prop_description() did not "
  1170. "fill in the description pointer");
  1171. *exp_err = FAIL;
  1172. } else {
  1173. *exp_err = PASS;
  1174. }
  1175. return (scf_ret);
  1176. }
  1177. /*
  1178. * scftest_tmpl_prop_units
  1179. * Purpose: Call scf_tmpl_prop_units()
  1180. * Parameters:
  1181. * input: scf_pg_tmpl_t *p; a property
  1182. * char **units: a pointer to the pointer for the units
  1183. * scf_error_t *exp_err: the expected error
  1184. * output: none
  1185. * Returns: The result of the scf_tmpl_prop_units call with PASS
  1186. * or FAIL in the exp_err pointer.
  1187. */
  1188. ssize_t
  1189. scftest_tmpl_prop_units(scf_prop_tmpl_t *p, const char *locale, char **units,
  1190. scf_error_t *exp_err) {
  1191. scf_error_t scf_err = SCF_ERROR_NONE;
  1192. int scf_ret;
  1193. if (*exp_err != SCF_ERROR_NONE) {
  1194. (void) fprintf(stdout, "--INFO: "
  1195. "Call scf_tmpl_prop_units() and expect an error\n");
  1196. } else {
  1197. (void) fprintf(stdout, "--INFO: "
  1198. "Call scf_tmpl_prop_units() and "
  1199. "return the propety units\n");
  1200. }
  1201. scf_ret = scf_tmpl_prop_units(p, locale, units);
  1202. scf_err = scf_error();
  1203. if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
  1204. /*
  1205. * An error was expected check that the error returned
  1206. * matches the expected error and report anomalies as
  1207. * well as success.
  1208. */
  1209. if (scf_err != *exp_err) {
  1210. (void) fprintf(stdout, "--DIAG: "
  1211. "scf_tmpl_prop_units() returned the wrong error\n\t"
  1212. "EXPECTED: %d \n\t"
  1213. "RETURNED: %d \n",
  1214. (unsigned int)*exp_err, scf_ret);
  1215. *exp_err = FAIL;
  1216. } else {
  1217. (void) fprintf(stdout, "--INFO: "
  1218. "scf_tmpl_prop_units() failed as expected\n");
  1219. *exp_err = PASS;
  1220. }
  1221. } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
  1222. /*
  1223. * An error was expected but the template came back as
  1224. * non-null which it should not have, therefore report
  1225. * the anomaly.
  1226. */
  1227. (void) fprintf(stdout, "--DIAG: "
  1228. "scf_tmpl_prop_units() did not fail as expected\n\t"
  1229. "RETURNED: 0x%p\n", (void *)*units);
  1230. if (*units)
  1231. free(*units);
  1232. *exp_err = FAIL;
  1233. } else if (scf_ret == -1) {
  1234. /*
  1235. * No error was expected, and template is still NULL
  1236. * report the anomaly.
  1237. */
  1238. (void) fprintf(stdout, "--DIAG: "
  1239. "scf_tmpl_prop_units() returned an error\n\t"
  1240. "ERROR: %u (%s)\n",
  1241. (unsigned int)scf_err, scf_strerror(scf_err));
  1242. *exp_err = FAIL;
  1243. } else if (*units == NULL) {
  1244. (void) fprintf(stdout, "--DIAG: "
  1245. "scf_tmpl_prop_units() did not fill in the units pointer");
  1246. *exp_err = FAIL;
  1247. } else {
  1248. *exp_err = PASS;
  1249. }
  1250. return (scf_ret);
  1251. }
  1252. /*
  1253. * scftest_tmpl_prop_visibility
  1254. * Purpose: Call scf_tmpl_prop_visibility()
  1255. * Parameters:
  1256. * input: scf_prop_tmpl_t *p: a property
  1257. * uint8_t *visibility: a pointer to the visibility flag
  1258. * scf_error_t *exp_err: the expected error
  1259. * output: none
  1260. * Returns: The result of the scf_tmpl_prop_visibility call with PASS
  1261. * or FAIL in the exp_err pointer.
  1262. */
  1263. int
  1264. scftest_tmpl_prop_visibility(scf_prop_tmpl_t *p, uint8_t *visibility,
  1265. scf_error_t *exp_err) {
  1266. scf_error_t scf_err = SCF_ERROR_NONE;
  1267. int scf_ret;
  1268. if (*exp_err != SCF_ERROR_NONE) {
  1269. (void) fprintf(stdout, "--INFO: "
  1270. "Call scf_tmpl_prop_visibility() and expect an error\n");
  1271. } else {
  1272. (void) fprintf(stdout, "--INFO: "
  1273. "Call scf_tmpl_prop_visibility() and return the "
  1274. "visibility flag\n");
  1275. }
  1276. scf_ret = scf_tmpl_prop_visibility(p, visibility);
  1277. scf_err = scf_error();
  1278. if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
  1279. /*
  1280. * An error was expected check that the error returned
  1281. * matches the expected error and report anomalies as
  1282. * well as success.
  1283. */
  1284. if (scf_err != *exp_err) {
  1285. (void) fprintf(stdout, "--DIAG: "
  1286. "scf_tmpl_prop_visibility() "
  1287. "returned the wrong error\n\t"
  1288. "EXPECTED: %d \n\t"
  1289. "RETURNED: %d \n",
  1290. (unsigned int)*exp_err, scf_ret);
  1291. *exp_err = FAIL;
  1292. } else {
  1293. (void) fprintf(stdout, "--INFO: "
  1294. "scf_tmpl_prop_visibility() failed as expected\n");
  1295. *exp_err = PASS;
  1296. }
  1297. } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
  1298. /*
  1299. * An error was expected but the template came back as
  1300. * non-null which it should not have, therefore report
  1301. * the anomaly.
  1302. */
  1303. (void) fprintf(stdout, "--DIAG: "
  1304. "scf_tmpl_prop_visibility() did not fail as expected\n\t"
  1305. "RETURNED: %u\n", (uint8_t)visibility);
  1306. *exp_err = FAIL;
  1307. } else if (scf_ret == -1) {
  1308. /*
  1309. * No error was expected, and template is still NULL
  1310. * report the anomaly.
  1311. */
  1312. (void) fprintf(stdout, "--DIAG: "
  1313. "scf_tmpl_prop_visibility() returned an error\n\t"
  1314. "ERROR: %u (%s)\n",
  1315. (unsigned int)scf_err, scf_strerror(scf_err));
  1316. *exp_err = FAIL;
  1317. } else {
  1318. *exp_err = PASS;
  1319. }
  1320. return (scf_ret);
  1321. }
  1322. /*
  1323. * scftest_tmpl_prop_cardinality
  1324. * Purpose: Call scf_tmpl_prop_cardinality()
  1325. * Parameters:
  1326. * input: scf_prop_tmpl_t *p: a property
  1327. * uint64_t *min: a pointer to the min
  1328. * uint64_t *max: a pointer to the max
  1329. * scf_error_t *exp_err: the expected error
  1330. * output: none
  1331. * Returns: The result of the scf_tmpl_prop_cardinality call with PASS
  1332. * or FAIL in the exp_err pointer.
  1333. */
  1334. int
  1335. scftest_tmpl_prop_cardinality(scf_prop_tmpl_t *p, uint64_t *min,
  1336. uint64_t *max, scf_error_t *exp_err) {
  1337. scf_error_t scf_err = SCF_ERROR_NONE;
  1338. int scf_ret;
  1339. if (*exp_err != SCF_ERROR_NONE) {
  1340. (void) fprintf(stdout, "--INFO: "
  1341. "Call scf_tmpl_prop_cardinality() and expect an error\n");
  1342. } else {
  1343. (void) fprintf(stdout, "--INFO: "
  1344. "Call scf_tmpl_prop_cardinality() and "
  1345. "return the cardinality flag\n");
  1346. }
  1347. scf_ret = scf_tmpl_prop_cardinality(p, min, max);
  1348. scf_err = scf_error();
  1349. if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
  1350. /*
  1351. * An error was expected check that the error returned
  1352. * matches the expected error and report anomalies as
  1353. * well as success.
  1354. */
  1355. if (scf_err != *exp_err) {
  1356. (void) fprintf(stdout, "--DIAG: "
  1357. "scf_tmpl_prop_cardinality() "
  1358. "returned the wrong error\n\t"
  1359. "EXPECTED: %d \n\t"
  1360. "RETURNED: %d \n",
  1361. (unsigned int)*exp_err, scf_ret);
  1362. *exp_err = FAIL;
  1363. } else {
  1364. (void) fprintf(stdout, "--INFO: "
  1365. "scf_tmpl_prop_cardinality() failed as expected\n");
  1366. *exp_err = PASS;
  1367. }
  1368. } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
  1369. /*
  1370. * An error was expected but the template came back as
  1371. * non-null which it should not have, therefore report
  1372. * the anomaly.
  1373. */
  1374. (void) fprintf(stdout, "--DIAG: "
  1375. "scf_tmpl_prop_cardinality() did not fail as expected\n"
  1376. "\tRETURNED: ");
  1377. if (min)
  1378. (void) fprintf(stdout, "min = %llu ", *min);
  1379. else
  1380. (void) fprintf(stdout, "min = NULL ");
  1381. if (max)
  1382. (void) fprintf(stdout, "max = %llu\n", *max);
  1383. else
  1384. (void) fprintf(stdout, "max = NULL\n");
  1385. (void) fprintf(stdout, "\tSCF_ERROR: %s\n",
  1386. scf_strerror(scf_error()));
  1387. *exp_err = FAIL;
  1388. } else if (scf_ret == -1) {
  1389. /*
  1390. * No error was expected, and template is still NULL
  1391. * report the anomaly.
  1392. */
  1393. (void) fprintf(stdout, "--DIAG: "
  1394. "scf_tmpl_prop_cardinality() returned an error\n\t"
  1395. "ERROR: %u (%s)\n",
  1396. (unsigned int)scf_err, scf_strerror(scf_err));
  1397. *exp_err = FAIL;
  1398. } else {
  1399. *exp_err = PASS;
  1400. }
  1401. return (scf_ret);
  1402. }
  1403. /*
  1404. * scftest_tmpl_prop_internal_seps
  1405. * Purpose: Call scf_tmpl_prop_internal_seps()
  1406. * Parameters:
  1407. * input: scf_prop_tmpl_t *p: a property
  1408. * char ***internal_seps: a pointer to a pointer
  1409. * to an array of characters
  1410. * scf_error_t *exp_err: the expected error
  1411. * output: none
  1412. * Returns: The result of the scf_tmpl_prop_internal_seps call with PASS
  1413. * or FAIL in the exp_err pointer.
  1414. */
  1415. int
  1416. scftest_tmpl_prop_internal_seps(scf_prop_tmpl_t *p, scf_values_t *seps,
  1417. scf_error_t *exp_err) {
  1418. scf_error_t scf_err = SCF_ERROR_NONE;
  1419. int i, scf_ret;
  1420. if (*exp_err != SCF_ERROR_NONE) {
  1421. (void) fprintf(stdout, "--INFO: "
  1422. "Call scf_tmpl_prop_internal_seps() and expect an error\n");
  1423. } else {
  1424. (void) fprintf(stdout, "--INFO: "
  1425. "Call scf_tmpl_prop_internal_seps() and return the list of "
  1426. "separators\n");
  1427. }
  1428. scf_ret = scf_tmpl_prop_internal_seps(p, seps);
  1429. scf_err = scf_error();
  1430. if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
  1431. /*
  1432. * An error was expected check that the error returned
  1433. * matches the expected error and report anomalies as
  1434. * well as success.
  1435. */
  1436. if (scf_err != *exp_err) {
  1437. (void) fprintf(stdout, "--DIAG: "
  1438. "scf_tmpl_prop_internal_seps() "
  1439. "returned the wrong error\n\t"
  1440. "EXPECTED: %d \n\t"
  1441. "RETURNED: %d \n",
  1442. (unsigned int)*exp_err, scf_ret);
  1443. *exp_err = FAIL;
  1444. } else {
  1445. (void) fprintf(stdout, "--INFO: "
  1446. "scf_tmpl_prop_internal_seps() "
  1447. "failed as expected\n");
  1448. *exp_err = PASS;
  1449. }
  1450. } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
  1451. /*
  1452. * An error was expected but the template came back as
  1453. * non-null which it should not have, therefore report
  1454. * the anomaly.
  1455. */
  1456. (void) fprintf(stdout, "--DIAG: "
  1457. "scf_tmpl_prop_internal_seps() did not fail as expected\n\t"
  1458. "RETURNED: ");
  1459. for (i = 0; seps->values.v_astring[i]; i++) {
  1460. (void) fprintf(stdout, "%c ",
  1461. (char)seps->values.v_astring[i]);
  1462. }
  1463. (void) fprintf(stdout, "\n");
  1464. *exp_err = FAIL;
  1465. } else if (scf_ret == -1) {
  1466. /*
  1467. * No error was expected, and template is still NULL
  1468. * report the anomaly.
  1469. */
  1470. (void) fprintf(stdout, "--DIAG: "
  1471. "scf_tmpl_prop_internal_seps() returned an error\n\t"
  1472. "ERROR: %u (%s)\n",
  1473. (unsigned int)scf_err, scf_strerror(scf_err));
  1474. *exp_err = FAIL;
  1475. } else {
  1476. *exp_err = PASS;
  1477. }
  1478. return (scf_ret);
  1479. }
  1480. /*
  1481. * scftest_tmpl_value_name_constraints
  1482. * Purpose: Call scf_tmpl_value_name_constraints()
  1483. * Parameters:
  1484. * input: scf_prop_tmpl_t *p : a property
  1485. * scf_values_t *vals : pointer to the scf_values_t
  1486. * scf_error_t *exp_err: the expected error
  1487. * output: none
  1488. * Returns: The result of the scf_tmpl_value_name_constraints call with PASS
  1489. * or FAIL in the exp_err pointer.
  1490. */
  1491. int
  1492. scftest_tmpl_value_name_constraints(scf_prop_tmpl_t *p, scf_values_t *vals,
  1493. scf_error_t *exp_err) {
  1494. scf_error_t scf_err = SCF_ERROR_NONE;
  1495. int scf_ret;
  1496. if (*exp_err != SCF_ERROR_NONE) {
  1497. (void) fprintf(stdout, "--INFO: "
  1498. "Call scf_tmpl_value_name_constraints() and "
  1499. "expect an error\n");
  1500. } else {
  1501. (void) fprintf(stdout, "--INFO: "
  1502. "Call scf_tmpl_value_name_constraints() and "
  1503. "return the values\n");
  1504. }
  1505. scf_ret = scf_tmpl_value_name_constraints(p, vals);
  1506. scf_err = scf_error();
  1507. if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
  1508. /*
  1509. * An error was expected check that the error returned
  1510. * matches the expected error and report anomalies as
  1511. * well as success.
  1512. */
  1513. if (scf_err != *exp_err) {
  1514. (void) fprintf(stdout, "--DIAG: "
  1515. "scf_tmpl_value_name_constraints() "
  1516. "returned the wrong error\n\t"
  1517. "EXPECTED: %d \n\t"
  1518. "RETURNED: %d \n",
  1519. (unsigned int)*exp_err, scf_ret);
  1520. *exp_err = FAIL;
  1521. } else {
  1522. (void) fprintf(stdout, "--INFO: "
  1523. "scf_tmpl_value_name_constraints() "
  1524. "failed as expected\n");
  1525. *exp_err = PASS;
  1526. }
  1527. } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
  1528. /*
  1529. * An error was expected but the template came back as
  1530. * non-null which it should not have, therefore report
  1531. * the anomaly.
  1532. */
  1533. (void) fprintf(stdout, "--DIAG: "
  1534. "scf_tmpl_value_name_constraints() did not "
  1535. "fail as expected\n\t"
  1536. "RETURNED: %s\n", (char *)vals->values.v_astring);
  1537. *exp_err = FAIL;
  1538. } else if (scf_ret == -1) {
  1539. /*
  1540. * No error was expected, and template is still NULL
  1541. * report the anomaly.
  1542. */
  1543. (void) fprintf(stdout, "--DIAG: "
  1544. "scf_tmpl_value_name_constraints() returned an error\n"
  1545. "ERROR: %u (%s)\n",
  1546. (unsigned int)scf_err, scf_strerror(scf_err));
  1547. *exp_err = FAIL;
  1548. } else {
  1549. *exp_err = PASS;
  1550. }
  1551. return (scf_ret);
  1552. }
  1553. /*
  1554. * scftest_tmpl_value_name_choices
  1555. * Purpose: Call scf_tmpl_value_name_choices()
  1556. * Parameters:
  1557. * input: scf_prop_tmpl_t *p : a property
  1558. * scf_values_t *vals : pointer to the scf_values_t
  1559. * scf_error_t *exp_err: the expected error
  1560. * output: none
  1561. * Returns: The result of the scf_tmpl_value_name_choices call with PASS
  1562. * or FAIL in the exp_err pointer.
  1563. */
  1564. int
  1565. scftest_tmpl_value_name_choices(scf_prop_tmpl_t *p, scf_values_t *vals,
  1566. scf_error_t *exp_err) {
  1567. scf_error_t scf_err = SCF_ERROR_NONE;
  1568. int scf_ret;
  1569. if (*exp_err != SCF_ERROR_NONE) {
  1570. (void) fprintf(stdout, "--INFO: "
  1571. "Call scf_tmpl_value_name_choices() and "
  1572. "expect an error\n");
  1573. } else {
  1574. (void) fprintf(stdout, "--INFO: "
  1575. "Call scf_tmpl_value_name_choices() and "
  1576. "return the values\n");
  1577. }
  1578. scf_ret = scf_tmpl_value_name_choices(p, vals);
  1579. scf_err = scf_error();
  1580. if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
  1581. /*
  1582. * An error was expected check that the error returned
  1583. * matches the expected error and report anomalies as
  1584. * well as success.
  1585. */
  1586. if (scf_err != *exp_err) {
  1587. (void) fprintf(stdout, "--DIAG: "
  1588. "scf_tmpl_value_name_choices() "
  1589. "returned the wrong error\n\t"
  1590. "EXPECTED: %d \n\t"
  1591. "RETURNED: %d \n",
  1592. (unsigned int)*exp_err, scf_ret);
  1593. *exp_err = FAIL;
  1594. } else {
  1595. (void) fprintf(stdout, "--INFO: "
  1596. "scf_tmpl_value_name_choices() "
  1597. "failed as expected\n");
  1598. *exp_err = PASS;
  1599. }
  1600. } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
  1601. /*
  1602. * An error was expected but the template came back as
  1603. * non-null which it s…

Large files files are truncated, but you can click here to view the full file