PageRenderTime 64ms CodeModel.GetById 21ms 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
  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 should not have, therefore report
  1604. * the anomaly.
  1605. */
  1606. (void) fprintf(stdout, "--DIAG: "
  1607. "scf_tmpl_value_name_choices() did not fail as expected\n\t"
  1608. "RETURNED: %s\n", (char *)vals->values.v_astring);
  1609. *exp_err = FAIL;
  1610. } else if (scf_ret == -1) {
  1611. /*
  1612. * No error was expected, and template is still NULL
  1613. * report the anomaly.
  1614. */
  1615. (void) fprintf(stdout, "--DIAG: "
  1616. "scf_tmpl_value_name_choices() returned an error\n"
  1617. "ERROR: %u (%s)\n",
  1618. (unsigned int)scf_err, scf_strerror(scf_err));
  1619. *exp_err = FAIL;
  1620. } else {
  1621. *exp_err = PASS;
  1622. }
  1623. return (scf_ret);
  1624. }
  1625. /*
  1626. * scftest_tmpl_value_count_range_constraints
  1627. * Purpose: Call scf_tmpl_value_count_range_constraints()
  1628. * Parameters:
  1629. * input: scf_prop_tmpl_t *p : a property
  1630. * scf_count_ranges_t *r : a set of count ranges
  1631. * output: none
  1632. * Returns: The result of the scf_tmpl_value_count_range_contraints call
  1633. * with PASS or FAIL in the exp_err pointer.
  1634. */
  1635. int
  1636. scftest_tmpl_value_count_range_constraints(scf_prop_tmpl_t *p,
  1637. scf_count_ranges_t *r, scf_error_t *exp_err) {
  1638. scf_error_t scf_err = SCF_ERROR_NONE;
  1639. int scf_ret;
  1640. if (*exp_err != SCF_ERROR_NONE) {
  1641. (void) fprintf(stdout, "--INFO: "
  1642. "Call scf_tmpl_value_count_range_constraints() and "
  1643. "expect an error\n");
  1644. } else {
  1645. (void) fprintf(stdout, "--INFO: "
  1646. "Call scf_tmpl_value_count_range_constraints() and "
  1647. "return the values\n");
  1648. }
  1649. scf_ret = scf_tmpl_value_count_range_constraints(p, r);
  1650. scf_err = scf_error();
  1651. if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
  1652. /*
  1653. * An error was expected check that the error returned
  1654. * matches the expected error and report anomalies as
  1655. * well as success.
  1656. */
  1657. if (scf_err != *exp_err) {
  1658. (void) fprintf(stdout, "--DIAG: "
  1659. "scf_tmpl_value_range_constraints() returned "
  1660. "the wrong error\n\t"
  1661. "EXPECTED: %d \n\t"
  1662. "RETURNED: %d \n",
  1663. (unsigned int)*exp_err, scf_ret);
  1664. *exp_err = FAIL;
  1665. } else {
  1666. (void) fprintf(stdout, "--INFO: "
  1667. "scf_tmpl_value_range_constraints() "
  1668. "failed as expected\n");
  1669. *exp_err = PASS;
  1670. }
  1671. } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
  1672. /*
  1673. * An error was expected but the template came back as
  1674. * non-null which it should not have, therefore report
  1675. * the anomaly.
  1676. */
  1677. (void) fprintf(stdout, "--DIAG: "
  1678. "scf_tmpl_value_range_constraints() did not "
  1679. "fail as expected\n\t"
  1680. "RETURNED: min = %llu max = %llu\n",
  1681. r->scr_min[0], r->scr_max[0]);
  1682. *exp_err = FAIL;
  1683. } else if (scf_ret == -1) {
  1684. /*
  1685. * No error was expected, and template is still NULL
  1686. * report the anomaly.
  1687. */
  1688. (void) fprintf(stdout, "--DIAG: "
  1689. "scf_tmpl_value_range_constraints() returned an error\n"
  1690. "ERROR: %u (%s)\n",
  1691. (unsigned int)scf_err, scf_strerror(scf_err));
  1692. *exp_err = FAIL;
  1693. } else {
  1694. *exp_err = PASS;
  1695. }
  1696. return (scf_ret);
  1697. }
  1698. /*
  1699. * scftest_tmpl_value_int_range_constraints
  1700. * Purpose: Call scf_tmpl_value_int_range_constraints()
  1701. * Parameters:
  1702. * input: scf_prop_tmpl_t *p : a property
  1703. * scf_int_ranges_t *r : a set of int ranges
  1704. * output: none
  1705. * Returns: The result of the scf_tmpl_value_int_range_constraints call
  1706. * with PASS or FAIL in the exp_err pointer.
  1707. */
  1708. int
  1709. scftest_tmpl_value_int_range_constraints(scf_prop_tmpl_t *p,
  1710. scf_int_ranges_t *r, scf_error_t *exp_err) {
  1711. scf_error_t scf_err = SCF_ERROR_NONE;
  1712. int scf_ret;
  1713. if (*exp_err != SCF_ERROR_NONE) {
  1714. (void) fprintf(stdout, "--INFO: "
  1715. "Call scf_tmpl_value_int_range_constraints() and "
  1716. "expect an error\n");
  1717. } else {
  1718. (void) fprintf(stdout, "--INFO: "
  1719. "Call scf_tmpl_value_int_range_constraints() and "
  1720. "return the values\n");
  1721. }
  1722. scf_ret = scf_tmpl_value_int_range_constraints(p, r);
  1723. scf_err = scf_error();
  1724. if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
  1725. /*
  1726. * An error was expected check that the error returned
  1727. * matches the expected error and report anomalies as
  1728. * well as success.
  1729. */
  1730. if (scf_err != *exp_err) {
  1731. (void) fprintf(stdout, "--DIAG: "
  1732. "scf_tmpl_value_range_constraints() returned "
  1733. "the wrong error\n\t"
  1734. "EXPECTED: %d \n\t"
  1735. "RETURNED: %d \n",
  1736. (unsigned int)*exp_err, scf_ret);
  1737. *exp_err = FAIL;
  1738. } else {
  1739. (void) fprintf(stdout, "--INFO: "
  1740. "scf_tmpl_value_range_constraints() "
  1741. "failed as expected\n");
  1742. *exp_err = PASS;
  1743. }
  1744. } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
  1745. /*
  1746. * An error was expected but the template came back as
  1747. * non-null which it should not have, therefore report
  1748. * the anomaly.
  1749. */
  1750. (void) fprintf(stdout, "--DIAG: "
  1751. "scf_tmpl_value_range_constraints() did not "
  1752. "fail as expected\n\t"
  1753. "RETURNED: min = %lld max = %lld\n",
  1754. r->sir_min[0], r->sir_max[0]);
  1755. *exp_err = FAIL;
  1756. } else if (scf_ret == -1) {
  1757. /*
  1758. * No error was expected, and template is still NULL
  1759. * report the anomaly.
  1760. */
  1761. (void) fprintf(stdout, "--DIAG: "
  1762. "scf_tmpl_value_range_constraints() returned an error\n"
  1763. "ERROR: %u (%s)\n",
  1764. (unsigned int)scf_err, scf_strerror(scf_err));
  1765. *exp_err = FAIL;
  1766. } else {
  1767. *exp_err = PASS;
  1768. }
  1769. return (scf_ret);
  1770. }
  1771. /*
  1772. * scftest_tmpl_value_count_range_choices
  1773. * Purpose: Call scf_tmpl_value_range_choices()
  1774. * Parameters:
  1775. * input: scf_prop_tmpl_t *p : a property
  1776. * scf_count_ranges_t *r : a set of count ranges
  1777. * scf_error_t *exp_err: the expected error
  1778. * output: none
  1779. * Returns: The result of the scf_tmpl_value_count_range_choices call
  1780. * with PASS or FAIL in the exp_err pointer.
  1781. */
  1782. int
  1783. scftest_tmpl_value_count_range_choices(scf_prop_tmpl_t *p,
  1784. scf_count_ranges_t *r, scf_error_t *exp_err) {
  1785. scf_error_t scf_err = SCF_ERROR_NONE;
  1786. int scf_ret;
  1787. if (*exp_err != SCF_ERROR_NONE) {
  1788. (void) fprintf(stdout, "--INFO: "
  1789. "Call scf_tmpl_value_range_choices() and "
  1790. "expect an error\n");
  1791. } else {
  1792. (void) fprintf(stdout, "--INFO: "
  1793. "Call scf_tmpl_value_range_choices() and "
  1794. "return the values\n");
  1795. }
  1796. scf_ret = scf_tmpl_value_count_range_choices(p, r);
  1797. scf_err = scf_error();
  1798. if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
  1799. /*
  1800. * An error was expected check that the error returned
  1801. * matches the expected error and report anomalies as
  1802. * well as success.
  1803. */
  1804. if (scf_err != *exp_err) {
  1805. (void) fprintf(stdout, "--DIAG: "
  1806. "scf_tmpl_value_range_choices() returned "
  1807. "the wrong error\n\t"
  1808. "EXPECTED: %d \n\t"
  1809. "RETURNED: %d \n",
  1810. (unsigned int)*exp_err, scf_ret);
  1811. *exp_err = FAIL;
  1812. } else {
  1813. (void) fprintf(stdout, "--INFO: "
  1814. "scf_tmpl_value_range_choices() "
  1815. "failed as expected\n");
  1816. *exp_err = PASS;
  1817. }
  1818. } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
  1819. /*
  1820. * An error was expected but the template came back as
  1821. * non-null which it should not have, therefore report
  1822. * the anomaly.
  1823. */
  1824. (void) fprintf(stdout, "--DIAG: "
  1825. "scf_tmpl_value_range_choices() did not "
  1826. "fail as expected\n\t"
  1827. "RETURNED: min = %llu max = %llu\n",
  1828. r->scr_min[0], r->scr_max[0]);
  1829. *exp_err = FAIL;
  1830. } else if (scf_ret == -1) {
  1831. /*
  1832. * No error was expected, and template is still NULL
  1833. * report the anomaly.
  1834. */
  1835. (void) fprintf(stdout, "--DIAG: "
  1836. "scf_tmpl_value_range_choices() returned an error\n"
  1837. "ERROR: %u (%s)\n",
  1838. (unsigned int)scf_err, scf_strerror(scf_err));
  1839. *exp_err = FAIL;
  1840. } else {
  1841. *exp_err = PASS;
  1842. }
  1843. return (scf_ret);
  1844. }
  1845. /*
  1846. * scftest_tmpl_value_int_range_choices
  1847. * Purpose: Call scf_tmpl_value_int_range_choices()
  1848. * Parameters:
  1849. * input: scf_prop_tmpl_t *p : a property
  1850. * scf_int_ranges_t *r : a set of int ranges
  1851. * output: none
  1852. * Returns: The result of the scf_tmpl_value_int_range_choices call
  1853. * with PASS or FAIL in the exp_err pointer.
  1854. */
  1855. int
  1856. scftest_tmpl_value_int_range_choices(scf_prop_tmpl_t *p, scf_int_ranges_t *r,
  1857. scf_error_t *exp_err) {
  1858. scf_error_t scf_err = SCF_ERROR_NONE;
  1859. int scf_ret;
  1860. if (*exp_err != SCF_ERROR_NONE) {
  1861. (void) fprintf(stdout, "--INFO: "
  1862. "Call scf_tmpl_value_range_choices() and "
  1863. "expect an error\n");
  1864. } else {
  1865. (void) fprintf(stdout, "--INFO: "
  1866. "Call scf_tmpl_value_range_choices() and "
  1867. "return the values\n");
  1868. }
  1869. scf_ret = scf_tmpl_value_int_range_choices(p, r);
  1870. scf_err = scf_error();
  1871. if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
  1872. /*
  1873. * An error was expected check that the error returned
  1874. * matches the expected error and report anomalies as
  1875. * well as success.
  1876. */
  1877. if (scf_err != *exp_err) {
  1878. (void) fprintf(stdout, "--DIAG: "
  1879. "scf_tmpl_value_range_choices() returned "
  1880. "the wrong error\n\t"
  1881. "EXPECTED: %d \n\t"
  1882. "RETURNED: %d \n",
  1883. (unsigned int)*exp_err, scf_ret);
  1884. *exp_err = FAIL;
  1885. } else {
  1886. (void) fprintf(stdout, "--INFO: "
  1887. "scf_tmpl_value_range_choices() "
  1888. "failed as expected\n");
  1889. *exp_err = PASS;
  1890. }
  1891. } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
  1892. /*
  1893. * An error was expected but the template came back as
  1894. * non-null which it should not have, therefore report
  1895. * the anomaly.
  1896. */
  1897. (void) fprintf(stdout, "--DIAG: "
  1898. "scf_tmpl_value_range_choices() did not "
  1899. "fail as expected\n\t"
  1900. "RETURNED: min = %lld max = %lld\n",
  1901. r->sir_min[0], r->sir_max[0]);
  1902. *exp_err = FAIL;
  1903. } else if (scf_ret == -1) {
  1904. /*
  1905. * No error was expected, and template is still NULL
  1906. * report the anomaly.
  1907. */
  1908. (void) fprintf(stdout, "--DIAG: "
  1909. "scf_tmpl_value_range_choices() returned an error\n"
  1910. "ERROR: %u (%s)\n",
  1911. (unsigned int)scf_err, scf_strerror(scf_err));
  1912. *exp_err = FAIL;
  1913. } else {
  1914. *exp_err = PASS;
  1915. }
  1916. return (scf_ret);
  1917. }
  1918. /*
  1919. * scftest_tmpl_value_common_name
  1920. * Purpose: Call scf_tmpl_value_common_name()
  1921. * Parameters:
  1922. * input: scf_prop_tmpl_t *p : a property pattern
  1923. * char *value : a value name
  1924. * char **cname : a pointer to the pointer
  1925. * for the common name
  1926. * scf_error_t *exp_err : the expected error
  1927. * output: none
  1928. * Returns: The result of the scf_tmpl_value_common_name call with PASS
  1929. * or FAIL in the exp_err pointer.
  1930. */
  1931. ssize_t
  1932. scftest_tmpl_value_common_name(scf_prop_tmpl_t *p, const char *locale,
  1933. const char *value, char **cname, scf_error_t *exp_err) {
  1934. scf_error_t scf_err = SCF_ERROR_NONE;
  1935. int scf_ret;
  1936. if (*exp_err != SCF_ERROR_NONE) {
  1937. (void) fprintf(stdout, "--INFO: "
  1938. "Call scf_tmpl_value_common_name() and expect an error\n");
  1939. } else {
  1940. (void) fprintf(stdout, "--INFO: "
  1941. "Call scf_tmpl_value_common_name() and return the values "
  1942. "common name\n");
  1943. }
  1944. scf_ret = scf_tmpl_value_common_name(p, locale, value, cname);
  1945. scf_err = scf_error();
  1946. if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
  1947. /*
  1948. * An error was expected check that the error returned
  1949. * matches the expected error and report anomalies as
  1950. * well as success.
  1951. */
  1952. if (scf_err != *exp_err) {
  1953. (void) fprintf(stdout, "--DIAG: "
  1954. "scf_tmpl_value_common_name() returned "
  1955. "the wrong error\n\t"
  1956. "EXPECTED: %d \n\t"
  1957. "RETURNED: %d \n",
  1958. (unsigned int)*exp_err, scf_ret);
  1959. *exp_err = FAIL;
  1960. } else {
  1961. (void) fprintf(stdout, "--INFO: "
  1962. "scf_tmpl_value_common_name() "
  1963. "failed as expected\n");
  1964. *exp_err = PASS;
  1965. }
  1966. } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
  1967. /*
  1968. * An error was expected but the template came back as
  1969. * non-null which it should not have, therefore report
  1970. * the anomaly.
  1971. */
  1972. (void) fprintf(stdout, "--DIAG: "
  1973. "scf_tmpl_value_common_name() did not fail as expected\n\t"
  1974. "RETURNED: 0x%p\n", (void *)*cname);
  1975. if (*cname)
  1976. free(*cname);
  1977. *exp_err = FAIL;
  1978. } else if (scf_ret == -1) {
  1979. /*
  1980. * No error was expected, and template is still NULL
  1981. * report the anomaly.
  1982. */
  1983. (void) fprintf(stdout, "--DIAG: "
  1984. "scf_tmpl_value_common_name() returned an error\n\t"
  1985. "ERROR: %u (%s)\n",
  1986. (unsigned int)scf_err, scf_strerror(scf_err));
  1987. *exp_err = FAIL;
  1988. } else if (*cname == NULL) {
  1989. (void) fprintf(stdout, "--DIAG: "
  1990. "scf_tmpl_value_common_name() did not "
  1991. "fill in the cname pointer");
  1992. *exp_err = FAIL;
  1993. } else {
  1994. *exp_err = PASS;
  1995. }
  1996. return (scf_ret);
  1997. }
  1998. /*
  1999. * scftest_tmpl_value_description
  2000. * Purpose: Call scf_tmpl_value_description()
  2001. * Parameters:
  2002. * input: scf_prop_tmpl_t *p : a property pattern
  2003. * char *value : a value name
  2004. * char **desc : a pointer to the pointer
  2005. * for the description
  2006. * scf_error_t *exp_err : the expected error
  2007. * output: none
  2008. * Returns: The result of the scf_tmpl_value_description call with PASS
  2009. * or FAIL in the exp_err pointer.
  2010. */
  2011. ssize_t
  2012. scftest_tmpl_value_description(scf_prop_tmpl_t *p, const char *locale,
  2013. const char *value, char **desc, scf_error_t *exp_err) {
  2014. scf_error_t scf_err = SCF_ERROR_NONE;
  2015. int scf_ret;
  2016. if (*exp_err != SCF_ERROR_NONE) {
  2017. (void) fprintf(stdout, "--INFO: "
  2018. "Call scf_tmpl_value_description() and expect an error\n");
  2019. } else {
  2020. (void) fprintf(stdout, "--INFO: "
  2021. "Call scf_tmpl_value_description() and return the values "
  2022. "common name\n");
  2023. }
  2024. scf_ret = scf_tmpl_value_description(p, locale, value, desc);
  2025. scf_err = scf_error();
  2026. if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
  2027. /*
  2028. * An error was expected check that the error returned
  2029. * matches the expected error and report anomalies as
  2030. * well as success.
  2031. */
  2032. if (scf_err != *exp_err) {
  2033. (void) fprintf(stdout, "--DIAG: "
  2034. "scf_tmpl_value_description() "
  2035. "returned the wrong error\n\t"
  2036. "EXPECTED: %d \n\t"
  2037. "RETURNED: %d \n",
  2038. (unsigned int)*exp_err, scf_ret);
  2039. *exp_err = FAIL;
  2040. } else {
  2041. (void) fprintf(stdout, "--INFO: "
  2042. "scf_tmpl_value_description() "
  2043. "failed as expected\n");
  2044. *exp_err = PASS;
  2045. }
  2046. } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
  2047. /*
  2048. * An error was expected but the template came back as
  2049. * non-null which it should not have, therefore report
  2050. * the anomaly.
  2051. */
  2052. (void) fprintf(stdout, "--DIAG: "
  2053. "scf_tmpl_value_description() did not fail as expected\n\t"
  2054. "RETURNED: 0x%p\n", (void *)*desc);
  2055. if (*desc)
  2056. free(*desc);
  2057. *exp_err = FAIL;
  2058. } else if (scf_ret == -1) {
  2059. /*
  2060. * No error was expected, and template is still NULL
  2061. * report the anomaly.
  2062. */
  2063. (void) fprintf(stdout, "--DIAG: "
  2064. "scf_tmpl_value_description() returned an error\n\t"
  2065. "ERROR: %u (%s)\n",
  2066. (unsigned int)scf_err, scf_strerror(scf_err));
  2067. *exp_err = FAIL;
  2068. } else if (*desc == NULL) {
  2069. (void) fprintf(stdout, "--DIAG: "
  2070. "scf_tmpl_value_description() did not "
  2071. "fill in the desc pointer");
  2072. *exp_err = FAIL;
  2073. } else {
  2074. *exp_err = PASS;
  2075. }
  2076. return (scf_ret);
  2077. }
  2078. /*
  2079. * scftest_tmpl_value_in_constraint
  2080. * Purpose: Call scf_tmpl_value_in_constraint()
  2081. * Parameters:
  2082. * input: scf_prop_tmpl_t *pt : a property pattern
  2083. * scf_value_t *v : value
  2084. * scf_tmpl_errors_t *errs: errors
  2085. * scf_error_t *exp_err *err : the expected error
  2086. * output: none
  2087. * Returns: The result of the scf_tmpl_value_in_constraint call with PASS
  2088. * or FAIL in the exp_err pointer.
  2089. */
  2090. int
  2091. scftest_tmpl_value_in_constraint(const scf_prop_tmpl_t *pt, scf_value_t *v,
  2092. scf_tmpl_errors_t **errs, scf_error_t *exp_err) {
  2093. scf_error_t scf_err = SCF_ERROR_NONE;
  2094. int scf_ret;
  2095. if (*exp_err != SCF_ERROR_NONE) {
  2096. (void) fprintf(stdout, "--INFO: "
  2097. "Call scf_tmpl_value_in_constraint() "
  2098. "and expect an error\n");
  2099. } else {
  2100. (void) fprintf(stdout, "--INFO: "
  2101. "Call scf_tmpl_value_in_constraint() and return the "
  2102. "value in constraint return value\n");
  2103. }
  2104. scf_ret = scf_tmpl_value_in_constraint(pt, v, errs);
  2105. scf_err = scf_error();
  2106. if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
  2107. /*
  2108. * An error was expected check that the error returned
  2109. * matches the expected error and report anomalies as
  2110. * well as success.
  2111. */
  2112. if (scf_err != *exp_err) {
  2113. (void) fprintf(stdout, "--DIAG: "
  2114. "scf_tmpl_value_in_constraint() returned "
  2115. "the wrong error\n\t"
  2116. "EXPECTED: %u (%s)\n\t"
  2117. "RETURNED: %u (%s)\n",
  2118. (unsigned int)*exp_err, scf_strerror(*exp_err),
  2119. (unsigned int)scf_err, scf_strerror(scf_err));
  2120. *exp_err = FAIL;
  2121. } else {
  2122. (void) fprintf(stdout, "--INFO: "
  2123. "scf_tmpl_value_in_constraint() "
  2124. "failed as expected scf_ret = %d\n", scf_ret);
  2125. *exp_err = PASS;
  2126. }
  2127. } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
  2128. /*
  2129. * An error was expected but the template came back as
  2130. * non-null which it should not have, therefore report
  2131. * the anomaly.
  2132. */
  2133. (void) fprintf(stdout, "--DIAG: "
  2134. "scf_tmpl_value_in_constraint() did not "
  2135. "fail as expected\n");
  2136. *exp_err = FAIL;
  2137. } else if (scf_ret == -1) {
  2138. /*
  2139. * No error was expected, and template is still NULL
  2140. * report the anomaly.
  2141. */
  2142. (void) fprintf(stdout, "--DIAG: "
  2143. "scf_tmpl_value_in_constraint() returned an error\n"
  2144. "\tRETURNED: %d\n"
  2145. "\tERROR: %u (%s)\n",
  2146. scf_ret, (unsigned int)scf_err, scf_strerror(scf_err));
  2147. *exp_err = FAIL;
  2148. } else {
  2149. if (scf_ret == 0) {
  2150. *exp_err = PASS;
  2151. (void) fprintf(stdout, "--INFO: "
  2152. "scf_tmpl_value_in_constraint() found the value "
  2153. "in the constraint\n");
  2154. } else if (scf_ret == 1) {
  2155. *exp_err = PASS;
  2156. (void) fprintf(stdout, "--INFO: "
  2157. "scf_tmpl_value_in_constraint() did not find the "
  2158. "value in the constraint\n");
  2159. } else {
  2160. *exp_err = FAIL;
  2161. (void) fprintf(stdout, "--INFO: "
  2162. "scf_tmpl_value_in_constraint() returned an "
  2163. "unexpected return value %d\n", scf_ret);
  2164. }
  2165. }
  2166. return (scf_ret);
  2167. }
  2168. /*
  2169. * verify_seps
  2170. * Purpose :
  2171. * Take an expected list of separators and verify that
  2172. * each expected separator is represented in the separator
  2173. * list.
  2174. *
  2175. * Parameters:
  2176. * exp_seps : expected separtor list
  2177. * seps : separator list
  2178. * cnt : expected number of separators
  2179. */
  2180. int
  2181. verify_seps(char *exp_seps, scf_values_t *seps, int cnt) {
  2182. int *fnd;
  2183. int i, j, ret = PASS;
  2184. if (seps->values.v_astring == NULL) {
  2185. (void) fprintf(stdout, "---DIAG: seps->values is NULL\n");
  2186. if (cnt > 0) {
  2187. ret = FAIL;
  2188. }
  2189. return (ret);
  2190. }
  2191. if ((fnd = malloc(sizeof (int) * cnt)) == NULL) {
  2192. (void) fprintf(stdout, "--DIAG: malloc failed with %d\n",
  2193. errno);
  2194. ret = FAIL;
  2195. return (ret);
  2196. }
  2197. bzero(fnd, sizeof (int) * cnt);
  2198. for (i = 0; i < seps->value_count; i++) {
  2199. for (j = 0; j < cnt; j++) {
  2200. if ((char *)exp_seps[j] ==
  2201. (char *)*seps->values.v_astring[i]) {
  2202. if (fnd[j] == 0) {
  2203. fnd[j] = 1;
  2204. (void) fprintf(stdout, "--INFO: "
  2205. "Found separator %c\n",
  2206. *seps->values.v_astring[i]);
  2207. break;
  2208. }
  2209. }
  2210. }
  2211. if (j == cnt) {
  2212. ret = FAIL;
  2213. (void) fprintf(stdout, "--DIAG: "
  2214. "Did not find separator %c in expected list\n",
  2215. *seps->values.v_astring[i]);
  2216. }
  2217. }
  2218. if (i != cnt) {
  2219. ret = FAIL;
  2220. (void) fprintf(stdout, "--DIAG: "
  2221. "Did not find all the separators in expected list\n");
  2222. }
  2223. free(fnd);
  2224. return (ret);
  2225. }
  2226. /*
  2227. * verify_constraint_names
  2228. * Purpose :
  2229. * Take a set of names and confirm that the names all exist
  2230. * in the values set provided.
  2231. *
  2232. * Parameters :
  2233. * exp_names : expected array of names (NULL terminated)
  2234. * names : scf_values_t structure containing names to be checked
  2235. */
  2236. int
  2237. verify_constraint_names(char **exp_names, scf_values_t *names) {
  2238. char **constraints;
  2239. int *fnd;
  2240. int cnt, i, j, ret = PASS;
  2241. cnt = 0;
  2242. while (exp_names[cnt] != NULL)
  2243. cnt++;
  2244. i = 0;
  2245. if ((fnd = malloc(sizeof (int) * cnt)) == NULL) {
  2246. (void) fprintf(stdout, "--DIAG: malloc failed with %d\n",
  2247. errno);
  2248. ret = FAIL;
  2249. return (ret);
  2250. }
  2251. bzero(fnd, sizeof (int) * cnt);
  2252. constraints = names->values.v_astring;
  2253. while (i < names->value_count != NULL) {
  2254. for (j = 0; j < cnt; j++) {
  2255. if (strcmp(constraints[i], exp_names[j]) == 0 &&
  2256. fnd[j] == 0) {
  2257. fnd[j] = 1;
  2258. (void) fprintf(stdout, "--INFO: "
  2259. "found constraint %s\n", constraints[i]);
  2260. break;
  2261. }
  2262. }
  2263. if (j == cnt) {
  2264. ret = FAIL;
  2265. (void) fprintf(stdout, "--DIAG: "
  2266. "Did not find constraint %s in expected list\n",
  2267. constraints[i]);
  2268. }
  2269. i++;
  2270. }
  2271. if (i != cnt) {
  2272. ret = FAIL;
  2273. (void) fprintf(stdout, "--DIAG: "
  2274. "Did not find all the constraints in expected list\n");
  2275. }
  2276. free(fnd);
  2277. return (ret);
  2278. }
  2279. /*
  2280. * b32_convert
  2281. * Purpose :
  2282. * Convert a set of strings to base 32 values.
  2283. *
  2284. * Parameters :
  2285. * vals : array of values.
  2286. * nvals : pointer to an array of the new values
  2287. * cnt : number of values to convert
  2288. */
  2289. int
  2290. b32_convert(char **vals, char **nvals, int cnt) {
  2291. FILE *fptr;
  2292. char *b32c;
  2293. char cmd[1024];
  2294. char *buf;
  2295. int i, cmdlen;
  2296. if ((b32c = getenv("BASE32_CODE")) == NULL) {
  2297. (void) fprintf(stdout, "--DIAG: "
  2298. "scftest_tmpl_add_value() unable to get the\n"
  2299. "base32 encoder environment variable\n");
  2300. return (1);
  2301. }
  2302. for (i = 0; i < cnt; i++) {
  2303. buf = malloc(SCFTEST_MAX_NAME_LENGTH);
  2304. cmdlen = strlen(b32c) + strlen(vals[i]);
  2305. if (cmdlen >= 1020) {
  2306. (void) fprintf(stdout, "--DIAG: "
  2307. "base 32 command is too long!\n"
  2308. "%s -e %s\n", b32c, vals[i]);
  2309. continue;
  2310. }
  2311. (void) snprintf(cmd, cmdlen + 5, "%s -e %s", b32c, vals[i]);
  2312. fptr = popen(cmd, "r");
  2313. (void) fgets(buf, SCFTEST_MAX_NAME_LENGTH, fptr);
  2314. buf[strlen(buf) - 1] = '\0';
  2315. (void) pclose(fptr);
  2316. nvals[i] = buf;
  2317. }
  2318. return (0);
  2319. }
  2320. /*
  2321. * scftest_tmpl_add_template
  2322. * Purpose :
  2323. * Take an array of value entries and turn them into
  2324. * repository property group and property group entries,
  2325. * that respresent a template entry.
  2326. * Parameters:
  2327. * svcname : pointer to the service name
  2328. * instname : pointer to an instance name (optional)
  2329. * pgname : pointer to the property group name
  2330. * values : pointer to tmpl_values_t array
  2331. * v_cnt : count of values
  2332. * pg_flag : property group flag
  2333. *
  2334. */
  2335. int
  2336. scftest_tmpl_add_template(char *instance, scftest_name_t *pname, int pgorprop,
  2337. tmpl_value_t values[], char **vallist, int vcnt, uint32_t pg_flag) {
  2338. scf_propertygroup_t *pg;
  2339. scf_handle_t *h;
  2340. scf_service_t *s;
  2341. scf_instance_t *i;
  2342. scf_scope_t *c;
  2343. scf_value_t ***v;
  2344. scftest_name_t *prop_name;
  2345. const char *scope, *svcname, *instname, *propertygroup, *property;
  2346. char local[6 * REP_PROTOCOL_NAME_LEN];
  2347. char *pgtype;
  2348. int j, k, cnt, totalvs;
  2349. int ret = 1;
  2350. int *nvals;
  2351. if (instance == NULL) {
  2352. (void) fprintf(stdout, "--DIAG: "
  2353. "scftest_tmpl_add_template() requires an\n"
  2354. "instance name\n");
  2355. goto out;
  2356. }
  2357. /* Create a connection handle */
  2358. if ((h = scf_handle_create(SCF_VERSION)) == NULL) {
  2359. (void) fprintf(stdout, "--DIAG: "
  2360. "scf_handle_create() failed\n\t"
  2361. "EXPECTED: handle != NULL, no error\n\t"
  2362. "RETURNED: handle == NULL, %s\n",
  2363. scf_strerror(scf_error()));
  2364. goto out;
  2365. } /* scf_handle_create() */
  2366. /* Bind the handle to the repository */
  2367. if (scf_handle_bind(h) != 0) {
  2368. (void) fprintf(stdout, "--DIAG: "
  2369. "Error connecting handle to repository: "
  2370. "scf_handle_bind() failed\n\t"
  2371. "EXPECTED: no error\n\t"
  2372. "RETURNED: %s\n",
  2373. scf_strerror(scf_error()));
  2374. goto out;
  2375. }
  2376. if (scftest_create_local_scope(h, &c) != 0 || c == NULL) {
  2377. (void) fprintf(stdout, "--DIAG: "
  2378. "Error retrieving scope: "
  2379. "scftest_handle_create_inited_scope() failed\n\t"
  2380. "EXPECTED: no error\n\t"
  2381. "RETURNED: %s\n",
  2382. scf_strerror(scf_error()));
  2383. goto out;
  2384. }
  2385. (void) strlcpy(local, instance, sizeof (local));
  2386. (void) scf_parse_svc_fmri(local, &scope, &svcname, &instname,
  2387. &propertygroup, &property);
  2388. s = scftest_lookup_create_item(h, c, svcname, NULL, NULL, NULL);
  2389. if (s == NULL) {
  2390. (void) fprintf(stdout, "--INFO: Unable to get service %s\n",
  2391. svcname);
  2392. goto out;
  2393. }
  2394. i = scftest_lookup_create_item(h, c, svcname, instname, NULL, NULL);
  2395. if (i == NULL) {
  2396. (void) fprintf(stdout, "--INFO: Unable to get instance %s\n",
  2397. instname);
  2398. goto out;
  2399. }
  2400. if ((pgorprop & TMPL_NOADD) == 0) {
  2401. if (pgorprop & TMPL_ADDPG) {
  2402. pgtype = "template_pg_pattern";
  2403. } else {
  2404. pgtype = "template_prop_pattern";
  2405. }
  2406. /*
  2407. * Add the property group (top level) repository entry,
  2408. * and then get the property group representing the newly
  2409. * added entry.
  2410. */
  2411. (void) scftest_instance_add_pgs(h, i, 1, pname, &pg_flag,
  2412. pgtype);
  2413. }
  2414. pg = (scf_propertygroup_t *)scftest_lookup_create_item(h, c, svcname,
  2415. instname, *pname, NULL);
  2416. if (pg == NULL) {
  2417. (void) fprintf(stdout, "--DIAG: The top level property group\n"
  2418. "%s was not added to the repository correctly\n",
  2419. (char *)pname);
  2420. goto out;
  2421. }
  2422. /*
  2423. * Total up the number of values to be added, and create the separate
  2424. * value lists for each entry to the repository.
  2425. */
  2426. totalvs = 0;
  2427. for (cnt = 0; cnt < vcnt; cnt++) {
  2428. values[cnt].pval = malloc(sizeof (char *) * values[cnt].pcnt);
  2429. for (j = totalvs, k = 0; j < totalvs + values[cnt].pcnt;
  2430. j++, k++)
  2431. values[cnt].pval[k] = vallist[j];
  2432. totalvs = totalvs + values[cnt].pcnt;
  2433. }
  2434. /*
  2435. * Allocate the needed memovry for the values to be stored into.
  2436. */
  2437. nvals = malloc(sizeof (int *) * vcnt);
  2438. prop_name = malloc(sizeof (scftest_name_t) * vcnt);
  2439. v = malloc(sizeof (scf_value_t *) * totalvs);
  2440. if (nvals == NULL || prop_name == NULL || v == NULL) {
  2441. (void) fprintf(stdout, "--DIAG: Unable to allocate the needed"
  2442. "memory to create the scf values to be added to the"
  2443. "repository\n");
  2444. goto out;
  2445. }
  2446. /*
  2447. * Walk the values creating the actual scf_value_t entries that
  2448. * will be added to the repository.
  2449. */
  2450. for (cnt = 0; cnt < vcnt; cnt++) {
  2451. nvals[cnt] = values[cnt].pcnt;
  2452. (void) strcpy((char *)prop_name[cnt], values[cnt].pname);
  2453. for (j = 0; j < values[cnt].pcnt; j++) {
  2454. (&v[cnt])[j] = (scf_value_t **)scf_value_create(h);
  2455. (void) scf_value_set_from_string((scf_value_t *)
  2456. (&v[cnt])[j], values[cnt].ptype,
  2457. values[cnt].pval[j]);
  2458. }
  2459. }
  2460. (void) scftest_pg_add_properties_with_values(h, pg, vcnt, prop_name,
  2461. nvals, (scf_value_t ***)v);
  2462. /*
  2463. * We have to refresh the instance so that the data is
  2464. * available to the running instance.
  2465. */
  2466. (void) smf_refresh_instance(instance);
  2467. free(nvals);
  2468. free(prop_name);
  2469. free(v);
  2470. /*
  2471. * This sleep in here, because it seems to take a few seconds for the
  2472. * refresh to happen and the tests will come in before the refresh
  2473. * complets. There is no way to make the refresh asynchronous at this
  2474. * time. The only other way to handle this is to check for the value we
  2475. * added but that's really what the test is doing. So we will give
  2476. * it an amount of time for update to happen, and if the test is failing
  2477. * due to ERR_NOT_FOUND then we know that we could be potentially racing
  2478. * past this 5 second sleep.
  2479. */
  2480. (void) sleep(5);
  2481. ret = 0;
  2482. out :
  2483. if (h)
  2484. scf_handle_destroy(h);
  2485. if (c)
  2486. scf_scope_destroy(c);
  2487. if (s)
  2488. scf_service_destroy(s);
  2489. if (i)
  2490. scf_instance_destroy(i);
  2491. return (ret);
  2492. }
  2493. /*
  2494. * scftest_tmpl_add_value
  2495. * Purpose :
  2496. * Take an array of value entries and turn them into
  2497. * repository property group and property group entries,
  2498. * that respresent a value entry.
  2499. * Parameters:
  2500. * svcname : pointer to the service name
  2501. * instname : pointer to an instance name (optional)
  2502. * pname : pointer to the property name
  2503. * values : pointer to tmpl_values_t array
  2504. * vcnt : count of values
  2505. * pg_flag : property group flag
  2506. *
  2507. */
  2508. int
  2509. /* ARGSUSED */
  2510. scftest_tmpl_add_value(char *instance, scftest_name_t *pname,
  2511. tmpl_value_t values[], char **vallist, int vcnt, uint32_t pg_flag) {
  2512. scf_propertygroup_t *pg;
  2513. scf_handle_t *h;
  2514. scf_service_t *s;
  2515. scf_instance_t *i;
  2516. scf_scope_t *c;
  2517. scf_value_t ***v;
  2518. scftest_name_t *prop_name;
  2519. const char *scope, *svcname, *instname, *propertygroup, *property;
  2520. char local[6 * REP_PROTOCOL_NAME_LEN];
  2521. int j, k, cnt, totalvs;
  2522. int ret = 1;
  2523. int *nvals;
  2524. FILE *fptr;
  2525. char *b32c;
  2526. if ((b32c = getenv("BASE32_CODE")) == NULL) {
  2527. (void) fprintf(stdout, "--DIAG: "
  2528. "scftest_tmpl_add_value() unable to get the\n"
  2529. "base32 encoder environment variable\n");
  2530. goto out;
  2531. }
  2532. /* Create a connection handle */
  2533. if ((h = scf_handle_create(SCF_VERSION)) == NULL) {
  2534. (void) fprintf(stdout, "--DIAG: "
  2535. "scf_handle_create() failed\n\t"
  2536. "EXPECTED: handle != NULL, no error\n\t"
  2537. "RETURNED: handle == NULL, %s\n",
  2538. scf_strerror(scf_error()));
  2539. goto out;
  2540. } /* scf_handle_create() */
  2541. /* Bind the handle to the repository */
  2542. if (scf_handle_bind(h) != 0) {
  2543. (void) fprintf(stdout, "--DIAG: "
  2544. "Error connecting handle to repository: "
  2545. "scf_handle_bind() failed\n\t"
  2546. "EXPECTED: no error\n\t"
  2547. "RETURNED: %s\n",
  2548. scf_strerror(scf_error()));
  2549. goto out;
  2550. }
  2551. if (scftest_create_local_scope(h, &c) != 0 || c == NULL) {
  2552. (void) fprintf(stdout, "--DIAG: "
  2553. "Error retrieving scope: "
  2554. "scftest_handle_create_inited_scope() failed\n\t"
  2555. "EXPECTED: no error\n\t"
  2556. "RETURNED: %s\n",
  2557. scf_strerror(scf_error()));
  2558. goto out;
  2559. }
  2560. (void) strlcpy(local, instance, sizeof (local));
  2561. (void) scf_parse_svc_fmri(local, &scope, &svcname, &instname,
  2562. &propertygroup, &property);
  2563. s = scftest_lookup_create_item(h, c, svcname, NULL, NULL, NULL);
  2564. if (s == NULL) {
  2565. (void) fprintf(stdout, "--INFO: Unable to get service %s\n",
  2566. svcname);
  2567. goto out;
  2568. }
  2569. i = scftest_lookup_create_item(h, c, svcname, instname, NULL, NULL);
  2570. if (i == NULL) {
  2571. (void) fprintf(stdout, "--INFO: Unable to get instance %s\n",
  2572. instname);
  2573. goto out;
  2574. }
  2575. pg = (scf_propertygroup_t *)scftest_lookup_create_item(h, c, svcname,
  2576. instname, *pname, NULL);
  2577. /*
  2578. * Allocated the needed space and initialize the bits to create
  2579. * the scf values to be added to the repository.
  2580. */
  2581. totalvs = 0;
  2582. nvals = malloc(sizeof (int *) * vcnt);
  2583. prop_name = malloc(sizeof (scftest_name_t) * vcnt);
  2584. for (cnt = 0; cnt < vcnt; cnt++) {
  2585. char buf[SCFTEST_MAX_NAME_LENGTH];
  2586. char cmd[1024];
  2587. int cmdlen, vlen;
  2588. /*
  2589. * Convert the pname to the base32 name that will be used
  2590. * in the repository entry. This is coded to do this
  2591. * work here, as there is no real reason to override this
  2592. * value as any testing of this will just turn up as NOT_FOUND
  2593. * errors, and can be simply tested outside of creating manual
  2594. * entries in the repository.
  2595. */
  2596. cmdlen = strlen(b32c) + strlen(values[cnt].pname);
  2597. if (cmdlen >= 1020) {
  2598. (void) fprintf(stdout, "--DIAG: "
  2599. "base 32 command is too long!\n"
  2600. "%s -e %s\n", b32c, values[cnt].pname);
  2601. goto out;
  2602. }
  2603. (void) snprintf(cmd, cmdlen + 5, "%s -e %s", b32c,
  2604. values[cnt].pname);
  2605. fptr = popen(cmd, "r");
  2606. (void) fgets(buf, SCFTEST_MAX_NAME_LENGTH, fptr);
  2607. buf[strlen(buf) - 1] = '\0';
  2608. vlen = strlen(buf) + strlen(vallist[totalvs]);
  2609. if (vlen >= SCFTEST_MAX_NAME_LENGTH) {
  2610. (void) fprintf(stdout, "--DIAG: "
  2611. "prop name value is too long!\n"
  2612. "value_%s%s\n", buf, vallist[totalvs]);
  2613. goto out;
  2614. }
  2615. (void) snprintf((char *)prop_name[cnt], vlen + 7, "value_%s%s",
  2616. buf, vallist[totalvs]);
  2617. (void) pclose(fptr);
  2618. totalvs++;
  2619. (void) fprintf(stdout, "prop_name[%d] = %s\n",
  2620. cnt, prop_name[cnt]);
  2621. /*
  2622. * Initialize the pvals portion of the values structure
  2623. * with the values in the list. Here we set the pcnt back by
  2624. * 1 to account for the postfix of the prop_name value.
  2625. */
  2626. values[cnt].pval = malloc(sizeof (char *) *
  2627. values[cnt].pcnt - 1);
  2628. for (j = totalvs, k = 0;
  2629. j < totalvs + (values[cnt].pcnt - 1); j++, k++)
  2630. values[cnt].pval[k] = vallist[j];
  2631. totalvs = totalvs + (values[cnt].pcnt - 1);
  2632. }
  2633. /*
  2634. * Allocate the memory the the scf values themselves.
  2635. */
  2636. v = malloc(sizeof (scf_value_t *) * totalvs);
  2637. /*
  2638. * Note : the pcnt is decremented by 1 here, to account for the
  2639. * postfix of the prop_name that is part of the value list.
  2640. */
  2641. for (cnt = 0; cnt < vcnt; cnt++) {
  2642. nvals[cnt] = values[cnt].pcnt - 1;
  2643. for (j = 0; j < values[cnt].pcnt - 1; j++) {
  2644. (&v[cnt])[j] = (scf_value_t **)scf_value_create(h);
  2645. (void) scf_value_set_from_string((scf_value_t *)
  2646. (&v[cnt])[j], values[cnt].ptype,
  2647. values[cnt].pval[j]);
  2648. }
  2649. }
  2650. (void) scftest_pg_add_properties_with_values(h, pg, vcnt, prop_name,
  2651. nvals, (scf_value_t ***)v);
  2652. (void) smf_refresh_instance(instance);
  2653. /*
  2654. * This sleep in here, because it seems to take a few seconds for the
  2655. * refresh to happen and the tests get will come in before the refresh
  2656. * complets. There is no way to make the refresh asynchronous at this
  2657. * time. The only other way to handle this is to check for the value we
  2658. * added but that's really what the test is doing. So we will give
  2659. * it an amount of time for update to happen, and if the test is failing
  2660. * due to ERR_NOT_FOUND then we know that we could be potentially racing
  2661. */
  2662. (void) sleep(5);
  2663. ret = 0;
  2664. out :
  2665. if (h)
  2666. scf_handle_destroy(h);
  2667. if (c)
  2668. scf_scope_destroy(c);
  2669. if (s)
  2670. scf_service_destroy(s);
  2671. if (i)
  2672. scf_instance_destroy(i);
  2673. return (ret);
  2674. }
  2675. /*
  2676. * scftest_tmpl_del_template_pg
  2677. * Purpose :
  2678. * Take a property group and remove it from the repository.
  2679. *
  2680. * Parameters:
  2681. * svcname : pointer to the service name
  2682. * instname : pointer to an instance name (optional)
  2683. * pname : pointer to the property group name
  2684. */
  2685. int
  2686. scftest_tmpl_del_template_pg(char *instance, scftest_name_t *pname) {
  2687. scf_handle_t *h;
  2688. scf_service_t *s;
  2689. scf_instance_t *i;
  2690. scf_scope_t *c;
  2691. const char *scope, *svcname, *instname, *propertygroup, *property;
  2692. char local[6 * REP_PROTOCOL_NAME_LEN];
  2693. int ret = 0;
  2694. /* Create a connection handle */
  2695. if ((h = scf_handle_create(SCF_VERSION)) == NULL) {
  2696. (void) fprintf(stdout, "--DIAG: "
  2697. "scf_handle_create() failed\n\t"
  2698. "EXPECTED: handle != NULL, no error\n\t"
  2699. "RETURNED: handle == NULL, %s\n",
  2700. scf_strerror(scf_error()));
  2701. ret = 1;
  2702. goto out;
  2703. }
  2704. /* Bind the handle to the repository */
  2705. if (scf_handle_bind(h) != 0) {
  2706. (void) fprintf(stdout, "--DIAG: "
  2707. "Error connecting handle to repository: "
  2708. "scf_handle_bind() failed\n\t"
  2709. "EXPECTED: no error\n\t"
  2710. "RETURNED: %s\n",
  2711. scf_strerror(scf_error()));
  2712. ret = 1;
  2713. goto out;
  2714. }
  2715. if (scftest_create_local_scope(h, &c) != 0 || c == NULL) {
  2716. (void) fprintf(stdout, "--DIAG: "
  2717. "Error retrieving scope: "
  2718. "scftest_handle_create_inited_scope() failed\n\t"
  2719. "EXPECTED: no error\n\t"
  2720. "RETURNED: %s\n",
  2721. scf_strerror(scf_error()));
  2722. ret = 1;
  2723. goto out;
  2724. }
  2725. (void) strlcpy(local, instance, sizeof (local));
  2726. (void) scf_parse_svc_fmri(local, &scope, &svcname, &instname,
  2727. &propertygroup, &property);
  2728. if ((s = scftest_get_service(h, c, svcname)) == NULL) {
  2729. (void) fprintf(stdout, "--DIAG: "
  2730. "Error looking up service '%s': "
  2731. "scftest_get_service() failed\n\t"
  2732. "EXPECTED: no error\n\t"
  2733. "RETURNED: %s\n",
  2734. svcname, scf_strerror(scf_error()));
  2735. ret = 1;
  2736. goto out;
  2737. }
  2738. if ((i = scftest_get_instance(h, c, svcname, instname)) == NULL) {
  2739. (void) fprintf(stdout, "--DIAG: "
  2740. "Error looking up instance '%s': "
  2741. "scftest_get_service() failed\n\t"
  2742. "EXPECTED: no error\n\t"
  2743. "RETURNED: %s\n",
  2744. svcname, scf_strerror(scf_error()));
  2745. ret = 1;
  2746. goto out;
  2747. }
  2748. (void) scftest_instance_delete_pgs(h, i, 1, pname);
  2749. out :
  2750. if (h)
  2751. scf_handle_destroy(h);
  2752. if (c)
  2753. scf_scope_destroy(c);
  2754. if (s)
  2755. scf_service_destroy(s);
  2756. if (i)
  2757. scf_instance_destroy(i);
  2758. return (ret);
  2759. }