/usr/src/suites/os/smf/tests/libscf-low/lib/libscftest-templates.c
C | 2991 lines | 1854 code | 232 blank | 905 comment | 690 complexity | 0a99059235dab8ed405f6e7239b9ce63 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception
- /*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License (the "License").
- * You may not use this file except in compliance with the License.
- *
- * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information: Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- */
- /*
- *
- * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
- #pragma ident "%Z%%M% %I% %E% SMI"
- /*
- * libscftest-property:
- * A library of test routines used in the property tests
- * for the mid level libscf API.
- * All functions in this file and in the accompanying include file
- * (must) have names begin with the string "scftest_".
- */
- #include <errno.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <strings.h>
- #include <unistd.h>
- #include <libscf.h>
- #include <libscf_priv.h>
- #include <libscftest-tmpl.h>
- #include <libscftest-low.h>
- /*
- * =====================================================
- * TEMPLATE FUNCTIONS
- * =====================================================
- */
- /*
- * scftest_tmpl_get_by_pg
- * Purpose: Call scf_tmpl_get_by_pg()
- * Parameters:
- * input: scf_propertygroup_t *pg; a property group to get
- * the template for
- * scf_pg_tmpl_t *template; a property group template
- * int flags: scf_tmpl_get_by_pg flags
- * scf_error_t *exp_err: the expected scf error code
- * output: none
- * Returns: The result of the scf_tmpl_get_by_pg call with PASS
- * or FAIL in the exp_err pointer.
- */
- int
- scftest_tmpl_get_by_pg(scf_propertygroup_t *pg, scf_pg_tmpl_t *template,
- int flags, scf_error_t *exp_err) {
- scf_error_t scf_err = SCF_ERROR_NONE;
- int scf_ret;
- if (*exp_err != SCF_ERROR_NONE) {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_get_by_pg() and expect an error\n");
- } else {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_get_by_pg() and return the "
- "pg template\n");
- }
- scf_ret = scf_tmpl_get_by_pg(pg, template, flags);
- scf_err = scf_error();
- /*
- * Check the returned data and expected error.
- */
- if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
- /*
- * An error was expected check that the error returned
- * matches the expected error and report anomalies as
- * well as success.
- */
- if (scf_err != *exp_err) {
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_get_by_pg() returned the "
- "wrong error\n\t"
- "EXPECTED: %u (%s)\n\t"
- "RETURNED: %u (%s)\n",
- (unsigned int)*exp_err, scf_strerror(*exp_err),
- (unsigned int)scf_err, scf_strerror(scf_err));
- *exp_err = FAIL;
- } else {
- (void) fprintf(stdout, "--INFO: "
- "scf_tmpl_get_by_pg() failed as expected %d\n",
- *exp_err);
- *exp_err = PASS;
- }
- } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
- /*
- * An error was expected but the template came back as
- * non-null which it should not have, therefore report
- * the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_get_by_pg() did not fail as expected\n"
- "\tRETURNED: %d\n"
- "\tSCF_ERROR: %s\n", scf_ret,
- scf_strerror(scf_error()));
- *exp_err = FAIL;
- } else if (scf_ret == -1) {
- /*
- * No error was expected, and template is still NULL
- * report the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_get_by_pg() returned an error\n"
- "\tERROR: %u (%s)\n",
- (unsigned int)scf_err, scf_strerror(scf_err));
- *exp_err = FAIL;
- } else {
- *exp_err = PASS;
- }
- return (scf_ret);
- }
- /*
- * scftest_tmpl_get_by_pg_name
- * Purpose: Call scf_tmpl_get_by_pg_name()
- * Parameters:
- * input: scf_handle_t *h; a handle
- * const char *fmri: an instance
- * const char *snapshot: a snapshot name
- * const char *pg: a property group
- * int flags: scf_tmpl_get_by_pg flags
- * scf_error_t *exp_err: the expected scf error code
- * output: none
- * Returns: The result of the scf_tmpl_get_by_pg_name call with PASS
- * or FAIL in the exp_err pointer.
- */
- int
- scftest_tmpl_get_by_pg_name(const char *fmri, const char *snapshot,
- const char *pg_name, const char *pg_type, scf_pg_tmpl_t *template,
- int flags, scf_error_t *exp_err) {
- scf_error_t scf_err = SCF_ERROR_NONE;
- int scf_ret;
- if (*exp_err != SCF_ERROR_NONE) {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_get_by_pg_name() and expect an error\n");
- } else {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_get_by_pg_name() and return the "
- "pg template\n");
- }
- scf_ret = scf_tmpl_get_by_pg_name(fmri, snapshot, pg_name, pg_type,
- template, flags);
- scf_err = scf_error();
- /*
- * Check the returned data and expected error.
- */
- if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
- /*
- * An error was expected check that the error returned
- * matches the expected error and report anomalies as
- * well as success.
- */
- if (scf_err != *exp_err) {
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_get_by_pg_name() returned the "
- "wrong error\n\t"
- "EXPECTED: %u (%s)\n\t"
- "RETURNED: %u (%s)\n",
- (unsigned int)*exp_err, scf_strerror(*exp_err),
- (unsigned int)scf_err, scf_strerror(scf_err));
- *exp_err = FAIL;
- } else {
- (void) fprintf(stdout, "--INFO: "
- "scf_tmpl_get_by_pg_name() failed as expected %d\n",
- *exp_err);
- *exp_err = PASS;
- }
- } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
- /*
- * An error was expected but the template came back as
- * non-null which it should not have, therefore report
- * the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_get_by_pg_name() did not fail as expected\n"
- "\tRETURNED: %d\n"
- "\tSCF_ERROR: %s\n", scf_ret,
- scf_strerror(scf_error()));
- *exp_err = FAIL;
- } else if (scf_ret == -1) {
- /*
- * No error was expected, and template is still NULL
- * report the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_get_by_pg_name() returned an error\n"
- "\tERROR: %u (%s)\n",
- (unsigned int)scf_err, scf_strerror(scf_err));
- *exp_err = FAIL;
- } else {
- *exp_err = PASS;
- }
- return (scf_ret);
- }
- /*
- * scftest_tmpl_get_by_prop
- * Purpose: Call scf_tmpl_get_by_prop()
- * Parameters:
- * input: scf_handle_t *h; a handle
- * const char *fmri: an instance
- * const char *snapshot: a snapshot name
- * const char *pg: a property group
- * int flags: scf_tmpl_get_by_prop flags
- * scf_error_t *exp_err: the expected scf error code
- * output: none
- * Returns: The result of the scf_tmpl_get_by_prop call with PASS
- * or FAIL in the exp_err pointer.
- */
- int
- scftest_tmpl_get_by_prop(scf_pg_tmpl_t *t, const char *prop,
- scf_prop_tmpl_t *property, int flags, scf_error_t *exp_err) {
- scf_error_t scf_err = SCF_ERROR_NONE;
- int scf_ret;
- if (*exp_err != SCF_ERROR_NONE) {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_get_by_prop() and expect an error\n");
- } else {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_get_by_prop() and return the prop "
- "template\n");
- }
- scf_ret = scf_tmpl_get_by_prop(t, prop, property, flags);
- scf_err = scf_error();
- if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
- /*
- * An error was expected check that the error returned
- * matches the expected error and report anomalies as
- * well as success.
- */
- if (scf_err != *exp_err) {
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_get_by_prop() returned the wrong "
- "error\n\t"
- "EXPECTED: %u (%s)\n\t"
- "RETURNED: %u (%s)\n",
- (unsigned int)*exp_err, scf_strerror(*exp_err),
- (unsigned int)scf_err, scf_strerror(scf_err));
- *exp_err = FAIL;
- } else {
- (void) fprintf(stdout, "--INFO: "
- "scf_tmpl_get_by_prop() failed as expected\n");
- *exp_err = PASS;
- }
- } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
- /*
- * An error was expected but the template came back as
- * non-null which it should not have, therefore report
- * the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_get_by_prop() did not fail as expected\n\t"
- "RETURNED: 0x%p\n", (void *)property);
- /* scf_prop_tmpl_free(template); */
- property = NULL;
- *exp_err = FAIL;
- } else if (scf_ret == -1) {
- /*
- * No error was expected, and template is still NULL
- * report the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_get_by_prop() returned an error\n\t"
- "ERROR: %u (%s)\n",
- (unsigned int)scf_err, scf_strerror(scf_err));
- *exp_err = FAIL;
- } else {
- *exp_err = PASS;
- }
- return (scf_ret);
- }
- /*
- * scftest_tmpl_iter_pgs
- * Purpose: Call scf_tmpl_iter_pgs()
- * Parameters:
- * input: scf_pg_tmpl_t *t: current template pointer
- * const char *fmri: an instance
- * const char *snapshot: a snapshot name
- * const char *pg: a property group
- * int flags: scf_tmpl_iter_pgs flags
- * scf_error_t *exp_err: the expected scf error code
- * output: none
- * Returns: The result of the scf_tmpl_iter_pgs call with PASS
- * or FAIL in the exp_err pointer.
- */
- int
- scftest_tmpl_iter_pgs(scf_pg_tmpl_t *t, const char *fmri,
- const char *snapshot, const char *pg_type, int flags,
- scf_error_t *exp_err) {
- scf_error_t scf_err = SCF_ERROR_NONE;
- int scf_ret;
- if (*exp_err != SCF_ERROR_NONE) {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_iter_pgs() and expect an error\n");
- } else {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_iter_pgs() and return the pg template\n");
- }
- scf_ret = scf_tmpl_iter_pgs(t, fmri, snapshot, pg_type, flags);
- scf_err = scf_error();
- if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
- /*
- * An error was expected check that the error returned
- * matches the expected error and report anomalies as
- * well as success.
- */
- if (scf_err != *exp_err) {
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_iter_pgs() returned the wrong error\n\t"
- "EXPECTED: %u (%s)\n\t"
- "RETURNED: %u (%s)\n",
- (unsigned int)*exp_err, scf_strerror(*exp_err),
- (unsigned int)scf_err, scf_strerror(scf_err));
- *exp_err = FAIL;
- } else {
- (void) fprintf(stdout, "--INFO: "
- "scf_tmpl_iter_pgs() failed as expected\n");
- *exp_err = PASS;
- }
- } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
- /*
- * An error was expected but the template came back as
- * non-null which it should not have, therefore report
- * the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_iter_pgs() did not fail as expected\n\t"
- "and returned a template\n\t"
- "RETURNED: %d\n", scf_ret);
- *exp_err = FAIL;
- } else if (scf_ret == -1) {
- /*
- * No error was expected, and template is still NULL
- * report the anomaly.
- */
- (void) fprintf(stdout, "--INFO: "
- "scf_tmpl_iter_pgs() returned an error, "
- "the end of property groups, %s\n",
- scf_strerror(scf_err));
- *exp_err = FAIL;
- } else {
- *exp_err = PASS;
- }
- return (scf_ret);
- }
- /*
- * scftest_tmpl_iter_props
- * Purpose: Call scf_tmpl_iter_props()
- * Parameters:
- * input: scf_pg_tmpl_t *t: current template pointer
- * scf_handle_t *h: a handle
- * const char *fmri: an instance
- * const char *snapshot: a snapshot name
- * const char *pg: a property group
- * int flags: scf_tmpl_iter_props flags
- * scf_error_t *exp_err: the expected scf error code
- * output: none
- * Returns: The result of the scf_tmpl_iter_props call with PASS
- * or FAIL in the exp_err pointer.
- */
- int
- scftest_tmpl_iter_props(scf_pg_tmpl_t *t, scf_prop_tmpl_t *p, int flags,
- scf_error_t *exp_err) {
- scf_error_t scf_err = SCF_ERROR_NONE;
- int scf_ret;
- if (*exp_err != SCF_ERROR_NONE) {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_iter_props() and expect an error\n");
- } else {
- (void) fprintf(stdout, "--INFO: Call scf_tmpl_iter_props() "
- "and return the prop template\n");
- }
- scf_ret = scf_tmpl_iter_props(t, p, flags);
- scf_err = scf_error();
- if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
- /*
- * An error was expected check that the error returned
- * matches the expected error and report anomalies as
- * well as success.
- */
- if (scf_err != *exp_err) {
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_iter_pgs() returned the wrong error\n\t"
- "EXPECTED: %u (%s)\n\t"
- "RETURNED: %u (%s)\n",
- (unsigned int)*exp_err, scf_strerror(*exp_err),
- (unsigned int)scf_err, scf_strerror(scf_err));
- *exp_err = FAIL;
- } else {
- (void) fprintf(stdout, "--INFO: "
- "scf_tmpl_iter_pgs() failed as expected\n");
- *exp_err = PASS;
- }
- } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
- /*
- * An error was expected but the template came back as
- * non-null which it should not have, therefore report
- * the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_iter_pgs() did not fail as expected\n\t"
- "and returned a prop\n\t"
- "RETURNED: %d\n", scf_ret);
- *exp_err = FAIL;
- } else if (scf_ret == -1) {
- /*
- * No error was expected, and template is still NULL
- * report the anomaly.
- */
- (void) fprintf(stdout, "--INFO: "
- "scf_tmpl_iter_pgs() returned an error, "
- "the end of property groups %s\n",
- scf_strerror(scf_err));
- *exp_err = FAIL;
- } else {
- *exp_err = PASS;
- }
- return (scf_ret);
- }
- /*
- * scftest_tmpl_pg_name
- * Purpose: Call scf_tmpl_pg_name()
- * Parameters:
- * input: scf_pg_tmpl_t *t; a template
- * char **name: a pointer to the pointer for the name
- * scf_error_t *exp_err: the expected error
- * output: none
- * Returns: The result of the scf_tmpl_pg_name call with PASS
- * or FAIL in the exp_err pointer.
- */
- ssize_t
- scftest_tmpl_pg_name(scf_pg_tmpl_t *t, char **name, scf_error_t *exp_err) {
- scf_error_t scf_err = SCF_ERROR_NONE;
- ssize_t scf_ret;
- if (*exp_err != SCF_ERROR_NONE) {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_pg_name() and expect an error\n");
- } else {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_pg_name() and return the pg name\n");
- }
- scf_ret = scf_tmpl_pg_name(t, name);
- scf_err = scf_error();
- if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
- /*
- * An error was expected check that the error returned
- * matches the expected error and report anomalies as
- * well as success.
- */
- if (scf_err != *exp_err) {
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_pg_name() returned the wrong error\n\t"
- "EXPECTED: %d \n\t"
- "RETURNED: %d \n",
- (unsigned int)*exp_err, scf_ret);
- *exp_err = FAIL;
- } else {
- (void) fprintf(stdout, "--INFO: "
- "scf_tmpl_pg_name() failed as expected\n");
- *exp_err = PASS;
- }
- } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
- /*
- * An error was expected but the template came back as
- * non-null which it should not have, therefore report
- * the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_pg_name() did not fail as expected\n\t"
- "RETURNED: 0x%p\n", (void *)*name);
- if (*name)
- free(*name);
- *exp_err = FAIL;
- } else if (scf_ret == -1) {
- /*
- * No error was expected, and template is still NULL
- * report the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_pg_name() returned an error\n\t"
- "ERROR: %u (%s)\n",
- (unsigned int)scf_err, scf_strerror(scf_err));
- *exp_err = FAIL;
- } else if (*name == NULL) {
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_pg_name() did not fill in the cname pointer");
- *exp_err = FAIL;
- } else {
- *exp_err = PASS;
- }
- return (scf_ret);
- }
- /*
- * scftest_tmpl_pg_common_name
- * Purpose: Call scf_tmpl_pg_common_name()
- * Parameters:
- * input: scf_pg_tmpl_t *t; a template
- * char **cname: a pointer to the pointer for the common name
- * scf_error_t *exp_err: the expected error
- * output: none
- * Returns: The result of the scf_tmpl_pg_common_name call with PASS
- * or FAIL in the exp_err pointer.
- */
- ssize_t
- scftest_tmpl_pg_common_name(scf_pg_tmpl_t *t, const char *locale, char **cname,
- scf_error_t *exp_err) {
- scf_error_t scf_err = SCF_ERROR_NONE;
- ssize_t scf_ret;
- if (*exp_err != SCF_ERROR_NONE) {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_pg_common_name() and expect an error\n");
- } else {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_pg_common_name() and "
- "return the pg template\n");
- }
- scf_ret = scf_tmpl_pg_common_name(t, locale, cname);
- scf_err = scf_error();
- if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
- /*
- * An error was expected check that the error returned
- * matches the expected error and report anomalies as
- * well as success.
- */
- if (scf_err != *exp_err) {
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_pg_common_name() "
- "returned the wrong error\n\t"
- "EXPECTED: %d \n\t"
- "RETURNED: %d \n",
- (unsigned int)*exp_err, scf_ret);
- *exp_err = FAIL;
- } else {
- (void) fprintf(stdout, "--INFO: "
- "scf_tmpl_pg_common_name() failed as expected\n");
- *exp_err = PASS;
- }
- } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
- /*
- * An error was expected but the template came back as
- * non-null which it should not have, therefore report
- * the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_pg_common_name() did not fail as expected\n\t"
- "RETURNED: 0x%p\n", (void *)*cname);
- if (*cname)
- free(*cname);
- *exp_err = FAIL;
- } else if (scf_ret == -1) {
- /*
- * No error was expected, and template is still NULL
- * report the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_pg_common_name() returned an error\n\t"
- "ERROR: %u (%s)\n",
- (unsigned int)scf_err, scf_strerror(scf_err));
- *exp_err = FAIL;
- } else if (*cname == NULL) {
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_pg_common_name() did not "
- "fill in the cname pointer");
- *exp_err = FAIL;
- } else {
- *exp_err = PASS;
- }
- return (scf_ret);
- }
- /*
- * scftest_tmpl_pg_description
- * Purpose: Call scf_tmpl_pg_description()
- * Parameters:
- * input: scf_pg_tmpl_t *t; a template
- * char **description: a pointer to the pointer for the description
- * scf_error_t *exp_err: the expected error
- * output: none
- * Returns: The result of the scf_tmpl_pg_description call with PASS
- * or FAIL in the exp_err pointer.
- */
- ssize_t
- scftest_tmpl_pg_description(scf_pg_tmpl_t *t, const char *locale,
- char **description, scf_error_t *exp_err) {
- scf_error_t scf_err = SCF_ERROR_NONE;
- ssize_t scf_ret;
- if (*exp_err != SCF_ERROR_NONE) {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_pg_description() and expect an error\n");
- } else {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_pg_description() and "
- "return the pg template\n");
- }
- scf_ret = scf_tmpl_pg_description(t, locale, description);
- scf_err = scf_error();
- if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
- /*
- * An error was expected check that the error returned
- * matches the expected error and report anomalies as
- * well as success.
- */
- if (scf_err != *exp_err) {
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_pg_description() "
- "returned the wrong error\n\t"
- "EXPECTED: %d \n\t"
- "RETURNED: %d \n",
- (unsigned int)*exp_err, scf_ret);
- *exp_err = FAIL;
- } else {
- (void) fprintf(stdout, "--INFO: "
- "scf_tmpl_pg_description() failed as expected\n");
- *exp_err = PASS;
- }
- } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
- /*
- * An error was expected but the template came back as
- * non-null which it should not have, therefore report
- * the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_pg_description() did not fail as expected\n\t"
- "RETURNED: 0x%p\n", (void *)*description);
- if (*description)
- free(*description);
- *exp_err = FAIL;
- } else if (scf_ret == -1) {
- /*
- * No error was expected, and template is still NULL
- * report the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_pg_description() returned an error\n\t"
- "ERROR: %u (%s)\n",
- (unsigned int)scf_err, scf_strerror(scf_err));
- *exp_err = FAIL;
- } else if (*description == NULL) {
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_pg_description() did not "
- "fill in the description pointer");
- *exp_err = FAIL;
- } else {
- *exp_err = PASS;
- }
- return (scf_ret);
- }
- /*
- * scftest_tmpl_pg_type
- * Purpose: Call scf_tmpl_pg_type()
- * Parameters:
- * input: scf_pg_tmpl_t *t; a template
- * char **type: a pointer to the pointer for the type
- * scf_error_t *exp_err: the expected error
- * output: none
- * Returns: The result of the scf_tmpl_pg_type call with PASS
- * or FAIL in the exp_err pointer.
- */
- ssize_t
- scftest_tmpl_pg_type(scf_pg_tmpl_t *t, char **type, scf_error_t *exp_err) {
- scf_error_t scf_err = SCF_ERROR_NONE;
- ssize_t scf_ret;
- if (*exp_err != SCF_ERROR_NONE) {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_pg_type() and expect an error\n");
- } else {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_pg_type() and return the pg template\n");
- }
- scf_ret = scf_tmpl_pg_type(t, type);
- scf_err = scf_error();
- if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
- /*
- * An error was expected check that the error returned
- * matches the expected error and report anomalies as
- * well as success.
- */
- if (scf_ret != *exp_err) {
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_pg_type() returned the wrong error\n\t"
- "EXPECTED: %d \n\t"
- "RETURNED: %d \n",
- (unsigned int)*exp_err, scf_ret);
- *exp_err = FAIL;
- } else {
- (void) fprintf(stdout, "--INFO: "
- "scf_tmpl_pg_type() failed as expected\n");
- *exp_err = PASS;
- }
- } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
- /*
- * An error was expected but the template came back as
- * non-null which it should not have, therefore report
- * the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_pg_type() did not fail as expected\n\t"
- "RETURNED: 0x%p\n", (void *)*type);
- if (*type)
- free(*type);
- *exp_err = FAIL;
- } else if (scf_ret == -1) {
- /*
- * No error was expected, and template is still NULL
- * report the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_pg_type() returned an error\n\t"
- "ERROR: %u (%s)\n",
- (unsigned int)scf_err, scf_strerror(scf_err));
- *exp_err = FAIL;
- } else if (*type == NULL) {
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_pg_type() did not fill in the type pointer");
- *exp_err = FAIL;
- } else {
- *exp_err = PASS;
- }
- return (scf_ret);
- }
- /*
- * scftest_tmpl_pg_required
- * Purpose: Call scf_tmpl_pg_required()
- * Parameters:
- * input: scf_pg_tmpl_t *t; a template
- * uint8_t *required: a pointer to the required flag
- * scf_error_t *exp_err: the expected error
- * output: none
- * Returns: The result of the scf_tmpl_pg_required call with PASS
- * or FAIL in the exp_err pointer.
- */
- int
- scftest_tmpl_pg_required(scf_pg_tmpl_t *t, uint8_t *required,
- scf_error_t *exp_err) {
- scf_error_t scf_err = SCF_ERROR_NONE;
- int scf_ret;
- if (*exp_err != SCF_ERROR_NONE) {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_pg_required() and expect an error\n");
- } else {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_pg_required() and return the pg template\n");
- }
- scf_ret = scf_tmpl_pg_required(t, required);
- scf_err = scf_error();
- if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
- /*
- * An error was expected check that the error returned
- * matches the expected error and report anomalies as
- * well as success.
- */
- if (scf_err != *exp_err) {
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_pg_required() "
- "returned the wrong error\n"
- "\tEXPECTED: %d \n"
- "\tRETURNED: %d \n"
- "\tSCF_ERROR: %s\n",
- (unsigned int)*exp_err, scf_err,
- scf_strerror(scf_error()));
- *exp_err = FAIL;
- } else {
- *exp_err = PASS;
- (void) fprintf(stdout, "--INFO: "
- "scf_tmpl_pg_required() failed as expected\n");
- }
- } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
- /*
- * An error was expected but the template came back as
- * non-null which it should not have, therefore report
- * the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_pg_required() did not fail as expected\n"
- "\tRETURNED : %d\n"
- "\trequired : %hu\n", scf_ret, (uint8_t)required);
- *exp_err = FAIL;
- } else if (scf_ret == -1) {
- /*
- * No error was expected, and template is still NULL
- * report the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_pg_required() returned an error\n\t"
- "ERROR: %u (%s)\n",
- (unsigned int)scf_err, scf_strerror(scf_err));
- *exp_err = FAIL;
- } else {
- *exp_err = PASS;
- }
- return (scf_ret);
- }
- /*
- * scftest_tmpl_prop_name
- * Purpose: Call scf_tmpl_prop_name()
- * Parameters:
- * input: scf_prop_tmpl_t *t: a template property
- * char **name: a pointer to the pointer for the name
- * scf_error_t *exp_err: the expected error
- * output: none
- * Returns: The result of the scf_tmpl_prop_name call with PASS
- * or FAIL in the exp_err pointer.
- */
- int
- scftest_tmpl_prop_name(scf_prop_tmpl_t *p, char **name, scf_error_t *exp_err) {
- scf_error_t scf_err = SCF_ERROR_NONE;
- int scf_ret;
- if (*exp_err != SCF_ERROR_NONE) {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_prop_name() and expect an error\n");
- } else {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_prop_name() and return the property name\n");
- }
- scf_ret = scf_tmpl_prop_name(p, name);
- scf_err = scf_error();
- if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
- /*
- * An error was expected check that the error returned
- * matches the expected error and report anomalies as
- * well as success.
- */
- if (scf_err != *exp_err) {
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_prop_name() returned the wrong error\n\t"
- "EXPECTED: %d \n\t"
- "RETURNED: %d \n",
- (unsigned int)*exp_err, scf_ret);
- *exp_err = FAIL;
- } else {
- (void) fprintf(stdout, "--INFO: "
- "scf_tmpl_prop_name() failed as expected\n");
- *exp_err = PASS;
- }
- } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
- /*
- * An error was expected but the template came back as
- * non-null which it should not have, therefore report
- * the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_prop_name() did not fail as expected\n\t"
- "RETURNED: 0x%p\n", (void *)*name);
- if (*name)
- free(*name);
- *exp_err = FAIL;
- } else if (scf_ret == -1) {
- /*
- * No error was expected, and template is still NULL
- * report the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_prop_name() returned an error\n\t"
- "ERROR: %u (%s)\n",
- (unsigned int)scf_err, scf_strerror(scf_err));
- *exp_err = FAIL;
- } else if (*name == NULL) {
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_prop_name() did not fill in the name pointer");
- *exp_err = FAIL;
- } else {
- *exp_err = PASS;
- }
- return (scf_ret);
- }
- /*
- * scftest_tmpl_prop_type
- * Purpose: Call scf_tmpl_prop_type()
- * Parameters:
- * input: scf_pg_tmpl_t *p; a property
- * scf_type_t *type: a pointer to the pointer for the type
- * scf_error_t *exp_err: the expected error
- * output: none
- * Returns: The result of the scf_tmpl_prop_type call with PASS
- * or FAIL in the exp_err pointer.
- */
- int
- scftest_tmpl_prop_type(scf_prop_tmpl_t *p, scf_type_t *type,
- scf_error_t *exp_err) {
- scf_error_t scf_err = SCF_ERROR_NONE;
- int scf_ret;
- if (*exp_err != SCF_ERROR_NONE) {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_prop_type() and expect an error\n");
- } else {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_prop_type() and return the propety type\n");
- }
- scf_ret = scf_tmpl_prop_type(p, type);
- scf_err = scf_error();
- if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
- /*
- * An error was expected check that the error returned
- * matches the expected error and report anomalies as
- * well as success.
- */
- if (scf_err != *exp_err) {
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_prop_type() returned the wrong error\n\t"
- "EXPECTED: %d \n\t"
- "RETURNED: %d \n",
- (unsigned int)*exp_err, scf_ret);
- *exp_err = FAIL;
- } else {
- (void) fprintf(stdout, "--INFO: "
- "scf_tmpl_prop_type() failed as expected\n");
- *exp_err = PASS;
- }
- } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
- /*
- * An error was expected but the template came back as
- * non-null which it should not have, therefore report
- * the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_prop_type() did not fail as expected\n\t"
- "RETURNED: 0x%p\n", (void *)*type);
- *exp_err = FAIL;
- } else if (scf_ret == -1) {
- /*
- * No error was expected, and template is still NULL
- * report the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_prop_type() returned an error\n\t"
- "ERROR: %u (%s)\n",
- (unsigned int)scf_err, scf_strerror(scf_err));
- *exp_err = FAIL;
- } else if (*type == NULL) {
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_prop_type() did not fill in the type pointer");
- *exp_err = FAIL;
- } else {
- *exp_err = PASS;
- }
- return (scf_ret);
- }
- /*
- * scftest_tmpl_prop_required
- * Purpose: Call scf_tmpl_prop_required()
- * Parameters:
- * input: scf_prop_tmpl_t *p: a property
- * uint8_t *required: a pointer to the required flag
- * scf_error_t *exp_err: the expected error
- * output: none
- * Returns: The result of the scf_tmpl_prop_required call with PASS
- * or FAIL in the exp_err pointer.
- */
- int
- scftest_tmpl_prop_required(scf_prop_tmpl_t *p, uint8_t *required,
- scf_error_t *exp_err) {
- scf_error_t scf_err = SCF_ERROR_NONE;
- int scf_ret;
- if (*exp_err != SCF_ERROR_NONE) {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_prop_required() and expect an error\n");
- } else {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_prop_required() and "
- "return the required flag\n");
- }
- scf_ret = scf_tmpl_prop_required(p, required);
- scf_err = scf_error();
- if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
- /*
- * An error was expected check that the error returned
- * matches the expected error and report anomalies as
- * well as success.
- */
- if (scf_err != *exp_err) {
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_prop_required() "
- "returned the wrong error\n\t"
- "EXPECTED: %d \n\t"
- "RETURNED: %d \n",
- (unsigned int)*exp_err, scf_ret);
- *exp_err = FAIL;
- } else {
- (void) fprintf(stdout, "--INFO: "
- "scf_tmpl_prop_required() failed as expected\n");
- *exp_err = PASS;
- }
- } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
- /*
- * An error was expected but the template came back as
- * non-null which it should not have, therefore report
- * the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_prop_required() did not fail as expected\n\t"
- "RETURNED: %u\n", (uint8_t)required);
- *exp_err = FAIL;
- } else if (scf_ret == -1) {
- /*
- * No error was expected, and template is still NULL
- * report the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_prop_required() returned an error\n\t"
- "ERROR: %u (%s)\n",
- (unsigned int)scf_err, scf_strerror(scf_err));
- *exp_err = FAIL;
- } else {
- *exp_err = PASS;
- }
- return (scf_ret);
- }
- /*
- * scftest_tmpl_prop_common_name
- * Purpose: Call scf_tmpl_prop_common_name()
- * Parameters:
- * input: scf_prop_tmpl_t *p: a property
- * char **cname: a pointer to the pointer for the common name
- * scf_error_t *exp_err: the expected error
- * output: none
- * Returns: The result of the scf_tmpl_prop_common_name call with PASS
- * or FAIL in the exp_err pointer.
- */
- ssize_t
- scftest_tmpl_prop_common_name(scf_prop_tmpl_t *p, const char *locale,
- char **cname, scf_error_t *exp_err) {
- scf_error_t scf_err = SCF_ERROR_NONE;
- int scf_ret;
- if (*exp_err != SCF_ERROR_NONE) {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_prop_common_name() and "
- "expect an error\n");
- } else {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_prop_common_name() and "
- "return the pg template\n");
- }
- scf_ret = scf_tmpl_prop_common_name(p, locale, cname);
- scf_err = scf_error();
- if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
- /*
- * An error was expected check that the error returned
- * matches the expected error and report anomalies as
- * well as success.
- */
- if (scf_err != *exp_err) {
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_prop_common_name() "
- "returned the wrong error\n\t"
- "EXPECTED: %d \n\t"
- "RETURNED: %d \n",
- (unsigned int)*exp_err, scf_ret);
- *exp_err = FAIL;
- } else {
- (void) fprintf(stdout, "--INFO: "
- "scf_tmpl_prop_common_name() failed as expected\n");
- *exp_err = PASS;
- }
- } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
- /*
- * An error was expected but the template came back as
- * non-null which it should not have, therefore report
- * the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_prop_common_name() did not fail as expected\n\t"
- "RETURNED: 0x%p\n", (void *)*cname);
- if (*cname)
- free(*cname);
- *exp_err = FAIL;
- } else if (scf_ret == -1) {
- /*
- * No error was expected, and template is still NULL
- * report the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_prop_common_name() returned an error\n\t"
- "ERROR: %u (%s)\n",
- (unsigned int)scf_err, scf_strerror(scf_err));
- *exp_err = FAIL;
- } else if (*cname == NULL) {
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_prop_common_name() did not "
- "fill in the cname pointer");
- *exp_err = FAIL;
- } else {
- *exp_err = PASS;
- }
- return (scf_ret);
- }
- /*
- * scftest_tmpl_prop_description
- * Purpose: Call scf_tmpl_prop_description()
- * Parameters:
- * input: scf_prop_tmpl_t *p: a property
- * char **description: a pointer to the pointer for the description
- * scf_error_t *exp_err: the expected error
- * output: none
- * Returns: The result of the scf_tmpl_prop_description call with PASS
- * or FAIL in the exp_err pointer.
- */
- ssize_t
- scftest_tmpl_prop_description(scf_prop_tmpl_t *p, const char *locale,
- char **description, scf_error_t *exp_err) {
- scf_error_t scf_err = SCF_ERROR_NONE;
- int scf_ret;
- if (*exp_err != SCF_ERROR_NONE) {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_prop_description() and "
- "expect an error\n");
- } else {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_prop_description() and "
- "return the pg template\n");
- }
- scf_ret = scf_tmpl_prop_description(p, locale, description);
- scf_err = scf_error();
- if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
- /*
- * An error was expected check that the error returned
- * matches the expected error and report anomalies as
- * well as success.
- */
- if (scf_err != *exp_err) {
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_prop_description() "
- "returned the wrong error\n\t"
- "EXPECTED: %d \n\t"
- "RETURNED: %d \n",
- (unsigned int)*exp_err, scf_err);
- *exp_err = FAIL;
- } else {
- (void) fprintf(stdout, "--INFO: "
- "scf_tmpl_prop_description() failed as expected\n");
- *exp_err = PASS;
- }
- } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
- /*
- * An error was expected but the template came back as
- * non-null which it should not have, therefore report
- * the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_prop_description() did not fail as expected\n\t"
- "RETURNED: 0x%p\n", (void *)*description);
- if (*description)
- free(*description);
- *exp_err = FAIL;
- } else if (scf_ret == -1) {
- /*
- * No error was expected, and template is still NULL
- * report the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_prop_description() returned an error\n\t"
- "ERROR: %u (%s)\n",
- (unsigned int)scf_err, scf_strerror(scf_err));
- *exp_err = FAIL;
- } else if (*description == NULL) {
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_prop_description() did not "
- "fill in the description pointer");
- *exp_err = FAIL;
- } else {
- *exp_err = PASS;
- }
- return (scf_ret);
- }
- /*
- * scftest_tmpl_prop_units
- * Purpose: Call scf_tmpl_prop_units()
- * Parameters:
- * input: scf_pg_tmpl_t *p; a property
- * char **units: a pointer to the pointer for the units
- * scf_error_t *exp_err: the expected error
- * output: none
- * Returns: The result of the scf_tmpl_prop_units call with PASS
- * or FAIL in the exp_err pointer.
- */
- ssize_t
- scftest_tmpl_prop_units(scf_prop_tmpl_t *p, const char *locale, char **units,
- scf_error_t *exp_err) {
- scf_error_t scf_err = SCF_ERROR_NONE;
- int scf_ret;
- if (*exp_err != SCF_ERROR_NONE) {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_prop_units() and expect an error\n");
- } else {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_prop_units() and "
- "return the propety units\n");
- }
- scf_ret = scf_tmpl_prop_units(p, locale, units);
- scf_err = scf_error();
- if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
- /*
- * An error was expected check that the error returned
- * matches the expected error and report anomalies as
- * well as success.
- */
- if (scf_err != *exp_err) {
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_prop_units() returned the wrong error\n\t"
- "EXPECTED: %d \n\t"
- "RETURNED: %d \n",
- (unsigned int)*exp_err, scf_ret);
- *exp_err = FAIL;
- } else {
- (void) fprintf(stdout, "--INFO: "
- "scf_tmpl_prop_units() failed as expected\n");
- *exp_err = PASS;
- }
- } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
- /*
- * An error was expected but the template came back as
- * non-null which it should not have, therefore report
- * the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_prop_units() did not fail as expected\n\t"
- "RETURNED: 0x%p\n", (void *)*units);
- if (*units)
- free(*units);
- *exp_err = FAIL;
- } else if (scf_ret == -1) {
- /*
- * No error was expected, and template is still NULL
- * report the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_prop_units() returned an error\n\t"
- "ERROR: %u (%s)\n",
- (unsigned int)scf_err, scf_strerror(scf_err));
- *exp_err = FAIL;
- } else if (*units == NULL) {
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_prop_units() did not fill in the units pointer");
- *exp_err = FAIL;
- } else {
- *exp_err = PASS;
- }
- return (scf_ret);
- }
- /*
- * scftest_tmpl_prop_visibility
- * Purpose: Call scf_tmpl_prop_visibility()
- * Parameters:
- * input: scf_prop_tmpl_t *p: a property
- * uint8_t *visibility: a pointer to the visibility flag
- * scf_error_t *exp_err: the expected error
- * output: none
- * Returns: The result of the scf_tmpl_prop_visibility call with PASS
- * or FAIL in the exp_err pointer.
- */
- int
- scftest_tmpl_prop_visibility(scf_prop_tmpl_t *p, uint8_t *visibility,
- scf_error_t *exp_err) {
- scf_error_t scf_err = SCF_ERROR_NONE;
- int scf_ret;
- if (*exp_err != SCF_ERROR_NONE) {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_prop_visibility() and expect an error\n");
- } else {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_prop_visibility() and return the "
- "visibility flag\n");
- }
- scf_ret = scf_tmpl_prop_visibility(p, visibility);
- scf_err = scf_error();
- if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
- /*
- * An error was expected check that the error returned
- * matches the expected error and report anomalies as
- * well as success.
- */
- if (scf_err != *exp_err) {
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_prop_visibility() "
- "returned the wrong error\n\t"
- "EXPECTED: %d \n\t"
- "RETURNED: %d \n",
- (unsigned int)*exp_err, scf_ret);
- *exp_err = FAIL;
- } else {
- (void) fprintf(stdout, "--INFO: "
- "scf_tmpl_prop_visibility() failed as expected\n");
- *exp_err = PASS;
- }
- } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
- /*
- * An error was expected but the template came back as
- * non-null which it should not have, therefore report
- * the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_prop_visibility() did not fail as expected\n\t"
- "RETURNED: %u\n", (uint8_t)visibility);
- *exp_err = FAIL;
- } else if (scf_ret == -1) {
- /*
- * No error was expected, and template is still NULL
- * report the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_prop_visibility() returned an error\n\t"
- "ERROR: %u (%s)\n",
- (unsigned int)scf_err, scf_strerror(scf_err));
- *exp_err = FAIL;
- } else {
- *exp_err = PASS;
- }
- return (scf_ret);
- }
- /*
- * scftest_tmpl_prop_cardinality
- * Purpose: Call scf_tmpl_prop_cardinality()
- * Parameters:
- * input: scf_prop_tmpl_t *p: a property
- * uint64_t *min: a pointer to the min
- * uint64_t *max: a pointer to the max
- * scf_error_t *exp_err: the expected error
- * output: none
- * Returns: The result of the scf_tmpl_prop_cardinality call with PASS
- * or FAIL in the exp_err pointer.
- */
- int
- scftest_tmpl_prop_cardinality(scf_prop_tmpl_t *p, uint64_t *min,
- uint64_t *max, scf_error_t *exp_err) {
- scf_error_t scf_err = SCF_ERROR_NONE;
- int scf_ret;
- if (*exp_err != SCF_ERROR_NONE) {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_prop_cardinality() and expect an error\n");
- } else {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_prop_cardinality() and "
- "return the cardinality flag\n");
- }
- scf_ret = scf_tmpl_prop_cardinality(p, min, max);
- scf_err = scf_error();
- if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
- /*
- * An error was expected check that the error returned
- * matches the expected error and report anomalies as
- * well as success.
- */
- if (scf_err != *exp_err) {
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_prop_cardinality() "
- "returned the wrong error\n\t"
- "EXPECTED: %d \n\t"
- "RETURNED: %d \n",
- (unsigned int)*exp_err, scf_ret);
- *exp_err = FAIL;
- } else {
- (void) fprintf(stdout, "--INFO: "
- "scf_tmpl_prop_cardinality() failed as expected\n");
- *exp_err = PASS;
- }
- } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
- /*
- * An error was expected but the template came back as
- * non-null which it should not have, therefore report
- * the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_prop_cardinality() did not fail as expected\n"
- "\tRETURNED: ");
- if (min)
- (void) fprintf(stdout, "min = %llu ", *min);
- else
- (void) fprintf(stdout, "min = NULL ");
- if (max)
- (void) fprintf(stdout, "max = %llu\n", *max);
- else
- (void) fprintf(stdout, "max = NULL\n");
- (void) fprintf(stdout, "\tSCF_ERROR: %s\n",
- scf_strerror(scf_error()));
- *exp_err = FAIL;
- } else if (scf_ret == -1) {
- /*
- * No error was expected, and template is still NULL
- * report the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_prop_cardinality() returned an error\n\t"
- "ERROR: %u (%s)\n",
- (unsigned int)scf_err, scf_strerror(scf_err));
- *exp_err = FAIL;
- } else {
- *exp_err = PASS;
- }
- return (scf_ret);
- }
- /*
- * scftest_tmpl_prop_internal_seps
- * Purpose: Call scf_tmpl_prop_internal_seps()
- * Parameters:
- * input: scf_prop_tmpl_t *p: a property
- * char ***internal_seps: a pointer to a pointer
- * to an array of characters
- * scf_error_t *exp_err: the expected error
- * output: none
- * Returns: The result of the scf_tmpl_prop_internal_seps call with PASS
- * or FAIL in the exp_err pointer.
- */
- int
- scftest_tmpl_prop_internal_seps(scf_prop_tmpl_t *p, scf_values_t *seps,
- scf_error_t *exp_err) {
- scf_error_t scf_err = SCF_ERROR_NONE;
- int i, scf_ret;
- if (*exp_err != SCF_ERROR_NONE) {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_prop_internal_seps() and expect an error\n");
- } else {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_prop_internal_seps() and return the list of "
- "separators\n");
- }
- scf_ret = scf_tmpl_prop_internal_seps(p, seps);
- scf_err = scf_error();
- if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
- /*
- * An error was expected check that the error returned
- * matches the expected error and report anomalies as
- * well as success.
- */
- if (scf_err != *exp_err) {
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_prop_internal_seps() "
- "returned the wrong error\n\t"
- "EXPECTED: %d \n\t"
- "RETURNED: %d \n",
- (unsigned int)*exp_err, scf_ret);
- *exp_err = FAIL;
- } else {
- (void) fprintf(stdout, "--INFO: "
- "scf_tmpl_prop_internal_seps() "
- "failed as expected\n");
- *exp_err = PASS;
- }
- } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
- /*
- * An error was expected but the template came back as
- * non-null which it should not have, therefore report
- * the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_prop_internal_seps() did not fail as expected\n\t"
- "RETURNED: ");
- for (i = 0; seps->values.v_astring[i]; i++) {
- (void) fprintf(stdout, "%c ",
- (char)seps->values.v_astring[i]);
- }
- (void) fprintf(stdout, "\n");
- *exp_err = FAIL;
- } else if (scf_ret == -1) {
- /*
- * No error was expected, and template is still NULL
- * report the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_prop_internal_seps() returned an error\n\t"
- "ERROR: %u (%s)\n",
- (unsigned int)scf_err, scf_strerror(scf_err));
- *exp_err = FAIL;
- } else {
- *exp_err = PASS;
- }
- return (scf_ret);
- }
- /*
- * scftest_tmpl_value_name_constraints
- * Purpose: Call scf_tmpl_value_name_constraints()
- * Parameters:
- * input: scf_prop_tmpl_t *p : a property
- * scf_values_t *vals : pointer to the scf_values_t
- * scf_error_t *exp_err: the expected error
- * output: none
- * Returns: The result of the scf_tmpl_value_name_constraints call with PASS
- * or FAIL in the exp_err pointer.
- */
- int
- scftest_tmpl_value_name_constraints(scf_prop_tmpl_t *p, scf_values_t *vals,
- scf_error_t *exp_err) {
- scf_error_t scf_err = SCF_ERROR_NONE;
- int scf_ret;
- if (*exp_err != SCF_ERROR_NONE) {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_value_name_constraints() and "
- "expect an error\n");
- } else {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_value_name_constraints() and "
- "return the values\n");
- }
- scf_ret = scf_tmpl_value_name_constraints(p, vals);
- scf_err = scf_error();
- if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
- /*
- * An error was expected check that the error returned
- * matches the expected error and report anomalies as
- * well as success.
- */
- if (scf_err != *exp_err) {
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_value_name_constraints() "
- "returned the wrong error\n\t"
- "EXPECTED: %d \n\t"
- "RETURNED: %d \n",
- (unsigned int)*exp_err, scf_ret);
- *exp_err = FAIL;
- } else {
- (void) fprintf(stdout, "--INFO: "
- "scf_tmpl_value_name_constraints() "
- "failed as expected\n");
- *exp_err = PASS;
- }
- } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
- /*
- * An error was expected but the template came back as
- * non-null which it should not have, therefore report
- * the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_value_name_constraints() did not "
- "fail as expected\n\t"
- "RETURNED: %s\n", (char *)vals->values.v_astring);
- *exp_err = FAIL;
- } else if (scf_ret == -1) {
- /*
- * No error was expected, and template is still NULL
- * report the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_value_name_constraints() returned an error\n"
- "ERROR: %u (%s)\n",
- (unsigned int)scf_err, scf_strerror(scf_err));
- *exp_err = FAIL;
- } else {
- *exp_err = PASS;
- }
- return (scf_ret);
- }
- /*
- * scftest_tmpl_value_name_choices
- * Purpose: Call scf_tmpl_value_name_choices()
- * Parameters:
- * input: scf_prop_tmpl_t *p : a property
- * scf_values_t *vals : pointer to the scf_values_t
- * scf_error_t *exp_err: the expected error
- * output: none
- * Returns: The result of the scf_tmpl_value_name_choices call with PASS
- * or FAIL in the exp_err pointer.
- */
- int
- scftest_tmpl_value_name_choices(scf_prop_tmpl_t *p, scf_values_t *vals,
- scf_error_t *exp_err) {
- scf_error_t scf_err = SCF_ERROR_NONE;
- int scf_ret;
- if (*exp_err != SCF_ERROR_NONE) {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_value_name_choices() and "
- "expect an error\n");
- } else {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_value_name_choices() and "
- "return the values\n");
- }
- scf_ret = scf_tmpl_value_name_choices(p, vals);
- scf_err = scf_error();
- if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
- /*
- * An error was expected check that the error returned
- * matches the expected error and report anomalies as
- * well as success.
- */
- if (scf_err != *exp_err) {
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_value_name_choices() "
- "returned the wrong error\n\t"
- "EXPECTED: %d \n\t"
- "RETURNED: %d \n",
- (unsigned int)*exp_err, scf_ret);
- *exp_err = FAIL;
- } else {
- (void) fprintf(stdout, "--INFO: "
- "scf_tmpl_value_name_choices() "
- "failed as expected\n");
- *exp_err = PASS;
- }
- } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
- /*
- * An error was expected but the template came back as
- * non-null which it should not have, therefore report
- * the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_value_name_choices() did not fail as expected\n\t"
- "RETURNED: %s\n", (char *)vals->values.v_astring);
- *exp_err = FAIL;
- } else if (scf_ret == -1) {
- /*
- * No error was expected, and template is still NULL
- * report the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_value_name_choices() returned an error\n"
- "ERROR: %u (%s)\n",
- (unsigned int)scf_err, scf_strerror(scf_err));
- *exp_err = FAIL;
- } else {
- *exp_err = PASS;
- }
- return (scf_ret);
- }
- /*
- * scftest_tmpl_value_count_range_constraints
- * Purpose: Call scf_tmpl_value_count_range_constraints()
- * Parameters:
- * input: scf_prop_tmpl_t *p : a property
- * scf_count_ranges_t *r : a set of count ranges
- * output: none
- * Returns: The result of the scf_tmpl_value_count_range_contraints call
- * with PASS or FAIL in the exp_err pointer.
- */
- int
- scftest_tmpl_value_count_range_constraints(scf_prop_tmpl_t *p,
- scf_count_ranges_t *r, scf_error_t *exp_err) {
- scf_error_t scf_err = SCF_ERROR_NONE;
- int scf_ret;
- if (*exp_err != SCF_ERROR_NONE) {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_value_count_range_constraints() and "
- "expect an error\n");
- } else {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_value_count_range_constraints() and "
- "return the values\n");
- }
- scf_ret = scf_tmpl_value_count_range_constraints(p, r);
- scf_err = scf_error();
- if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
- /*
- * An error was expected check that the error returned
- * matches the expected error and report anomalies as
- * well as success.
- */
- if (scf_err != *exp_err) {
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_value_range_constraints() returned "
- "the wrong error\n\t"
- "EXPECTED: %d \n\t"
- "RETURNED: %d \n",
- (unsigned int)*exp_err, scf_ret);
- *exp_err = FAIL;
- } else {
- (void) fprintf(stdout, "--INFO: "
- "scf_tmpl_value_range_constraints() "
- "failed as expected\n");
- *exp_err = PASS;
- }
- } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
- /*
- * An error was expected but the template came back as
- * non-null which it should not have, therefore report
- * the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_value_range_constraints() did not "
- "fail as expected\n\t"
- "RETURNED: min = %llu max = %llu\n",
- r->scr_min[0], r->scr_max[0]);
- *exp_err = FAIL;
- } else if (scf_ret == -1) {
- /*
- * No error was expected, and template is still NULL
- * report the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_value_range_constraints() returned an error\n"
- "ERROR: %u (%s)\n",
- (unsigned int)scf_err, scf_strerror(scf_err));
- *exp_err = FAIL;
- } else {
- *exp_err = PASS;
- }
- return (scf_ret);
- }
- /*
- * scftest_tmpl_value_int_range_constraints
- * Purpose: Call scf_tmpl_value_int_range_constraints()
- * Parameters:
- * input: scf_prop_tmpl_t *p : a property
- * scf_int_ranges_t *r : a set of int ranges
- * output: none
- * Returns: The result of the scf_tmpl_value_int_range_constraints call
- * with PASS or FAIL in the exp_err pointer.
- */
- int
- scftest_tmpl_value_int_range_constraints(scf_prop_tmpl_t *p,
- scf_int_ranges_t *r, scf_error_t *exp_err) {
- scf_error_t scf_err = SCF_ERROR_NONE;
- int scf_ret;
- if (*exp_err != SCF_ERROR_NONE) {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_value_int_range_constraints() and "
- "expect an error\n");
- } else {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_value_int_range_constraints() and "
- "return the values\n");
- }
- scf_ret = scf_tmpl_value_int_range_constraints(p, r);
- scf_err = scf_error();
- if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
- /*
- * An error was expected check that the error returned
- * matches the expected error and report anomalies as
- * well as success.
- */
- if (scf_err != *exp_err) {
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_value_range_constraints() returned "
- "the wrong error\n\t"
- "EXPECTED: %d \n\t"
- "RETURNED: %d \n",
- (unsigned int)*exp_err, scf_ret);
- *exp_err = FAIL;
- } else {
- (void) fprintf(stdout, "--INFO: "
- "scf_tmpl_value_range_constraints() "
- "failed as expected\n");
- *exp_err = PASS;
- }
- } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
- /*
- * An error was expected but the template came back as
- * non-null which it should not have, therefore report
- * the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_value_range_constraints() did not "
- "fail as expected\n\t"
- "RETURNED: min = %lld max = %lld\n",
- r->sir_min[0], r->sir_max[0]);
- *exp_err = FAIL;
- } else if (scf_ret == -1) {
- /*
- * No error was expected, and template is still NULL
- * report the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_value_range_constraints() returned an error\n"
- "ERROR: %u (%s)\n",
- (unsigned int)scf_err, scf_strerror(scf_err));
- *exp_err = FAIL;
- } else {
- *exp_err = PASS;
- }
- return (scf_ret);
- }
- /*
- * scftest_tmpl_value_count_range_choices
- * Purpose: Call scf_tmpl_value_range_choices()
- * Parameters:
- * input: scf_prop_tmpl_t *p : a property
- * scf_count_ranges_t *r : a set of count ranges
- * scf_error_t *exp_err: the expected error
- * output: none
- * Returns: The result of the scf_tmpl_value_count_range_choices call
- * with PASS or FAIL in the exp_err pointer.
- */
- int
- scftest_tmpl_value_count_range_choices(scf_prop_tmpl_t *p,
- scf_count_ranges_t *r, scf_error_t *exp_err) {
- scf_error_t scf_err = SCF_ERROR_NONE;
- int scf_ret;
- if (*exp_err != SCF_ERROR_NONE) {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_value_range_choices() and "
- "expect an error\n");
- } else {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_value_range_choices() and "
- "return the values\n");
- }
- scf_ret = scf_tmpl_value_count_range_choices(p, r);
- scf_err = scf_error();
- if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
- /*
- * An error was expected check that the error returned
- * matches the expected error and report anomalies as
- * well as success.
- */
- if (scf_err != *exp_err) {
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_value_range_choices() returned "
- "the wrong error\n\t"
- "EXPECTED: %d \n\t"
- "RETURNED: %d \n",
- (unsigned int)*exp_err, scf_ret);
- *exp_err = FAIL;
- } else {
- (void) fprintf(stdout, "--INFO: "
- "scf_tmpl_value_range_choices() "
- "failed as expected\n");
- *exp_err = PASS;
- }
- } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
- /*
- * An error was expected but the template came back as
- * non-null which it should not have, therefore report
- * the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_value_range_choices() did not "
- "fail as expected\n\t"
- "RETURNED: min = %llu max = %llu\n",
- r->scr_min[0], r->scr_max[0]);
- *exp_err = FAIL;
- } else if (scf_ret == -1) {
- /*
- * No error was expected, and template is still NULL
- * report the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_value_range_choices() returned an error\n"
- "ERROR: %u (%s)\n",
- (unsigned int)scf_err, scf_strerror(scf_err));
- *exp_err = FAIL;
- } else {
- *exp_err = PASS;
- }
- return (scf_ret);
- }
- /*
- * scftest_tmpl_value_int_range_choices
- * Purpose: Call scf_tmpl_value_int_range_choices()
- * Parameters:
- * input: scf_prop_tmpl_t *p : a property
- * scf_int_ranges_t *r : a set of int ranges
- * output: none
- * Returns: The result of the scf_tmpl_value_int_range_choices call
- * with PASS or FAIL in the exp_err pointer.
- */
- int
- scftest_tmpl_value_int_range_choices(scf_prop_tmpl_t *p, scf_int_ranges_t *r,
- scf_error_t *exp_err) {
- scf_error_t scf_err = SCF_ERROR_NONE;
- int scf_ret;
- if (*exp_err != SCF_ERROR_NONE) {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_value_range_choices() and "
- "expect an error\n");
- } else {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_value_range_choices() and "
- "return the values\n");
- }
- scf_ret = scf_tmpl_value_int_range_choices(p, r);
- scf_err = scf_error();
- if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
- /*
- * An error was expected check that the error returned
- * matches the expected error and report anomalies as
- * well as success.
- */
- if (scf_err != *exp_err) {
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_value_range_choices() returned "
- "the wrong error\n\t"
- "EXPECTED: %d \n\t"
- "RETURNED: %d \n",
- (unsigned int)*exp_err, scf_ret);
- *exp_err = FAIL;
- } else {
- (void) fprintf(stdout, "--INFO: "
- "scf_tmpl_value_range_choices() "
- "failed as expected\n");
- *exp_err = PASS;
- }
- } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
- /*
- * An error was expected but the template came back as
- * non-null which it should not have, therefore report
- * the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_value_range_choices() did not "
- "fail as expected\n\t"
- "RETURNED: min = %lld max = %lld\n",
- r->sir_min[0], r->sir_max[0]);
- *exp_err = FAIL;
- } else if (scf_ret == -1) {
- /*
- * No error was expected, and template is still NULL
- * report the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_value_range_choices() returned an error\n"
- "ERROR: %u (%s)\n",
- (unsigned int)scf_err, scf_strerror(scf_err));
- *exp_err = FAIL;
- } else {
- *exp_err = PASS;
- }
- return (scf_ret);
- }
- /*
- * scftest_tmpl_value_common_name
- * Purpose: Call scf_tmpl_value_common_name()
- * Parameters:
- * input: scf_prop_tmpl_t *p : a property pattern
- * char *value : a value name
- * char **cname : a pointer to the pointer
- * for the common name
- * scf_error_t *exp_err : the expected error
- * output: none
- * Returns: The result of the scf_tmpl_value_common_name call with PASS
- * or FAIL in the exp_err pointer.
- */
- ssize_t
- scftest_tmpl_value_common_name(scf_prop_tmpl_t *p, const char *locale,
- const char *value, char **cname, scf_error_t *exp_err) {
- scf_error_t scf_err = SCF_ERROR_NONE;
- int scf_ret;
- if (*exp_err != SCF_ERROR_NONE) {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_value_common_name() and expect an error\n");
- } else {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_value_common_name() and return the values "
- "common name\n");
- }
- scf_ret = scf_tmpl_value_common_name(p, locale, value, cname);
- scf_err = scf_error();
- if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
- /*
- * An error was expected check that the error returned
- * matches the expected error and report anomalies as
- * well as success.
- */
- if (scf_err != *exp_err) {
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_value_common_name() returned "
- "the wrong error\n\t"
- "EXPECTED: %d \n\t"
- "RETURNED: %d \n",
- (unsigned int)*exp_err, scf_ret);
- *exp_err = FAIL;
- } else {
- (void) fprintf(stdout, "--INFO: "
- "scf_tmpl_value_common_name() "
- "failed as expected\n");
- *exp_err = PASS;
- }
- } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
- /*
- * An error was expected but the template came back as
- * non-null which it should not have, therefore report
- * the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_value_common_name() did not fail as expected\n\t"
- "RETURNED: 0x%p\n", (void *)*cname);
- if (*cname)
- free(*cname);
- *exp_err = FAIL;
- } else if (scf_ret == -1) {
- /*
- * No error was expected, and template is still NULL
- * report the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_value_common_name() returned an error\n\t"
- "ERROR: %u (%s)\n",
- (unsigned int)scf_err, scf_strerror(scf_err));
- *exp_err = FAIL;
- } else if (*cname == NULL) {
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_value_common_name() did not "
- "fill in the cname pointer");
- *exp_err = FAIL;
- } else {
- *exp_err = PASS;
- }
- return (scf_ret);
- }
- /*
- * scftest_tmpl_value_description
- * Purpose: Call scf_tmpl_value_description()
- * Parameters:
- * input: scf_prop_tmpl_t *p : a property pattern
- * char *value : a value name
- * char **desc : a pointer to the pointer
- * for the description
- * scf_error_t *exp_err : the expected error
- * output: none
- * Returns: The result of the scf_tmpl_value_description call with PASS
- * or FAIL in the exp_err pointer.
- */
- ssize_t
- scftest_tmpl_value_description(scf_prop_tmpl_t *p, const char *locale,
- const char *value, char **desc, scf_error_t *exp_err) {
- scf_error_t scf_err = SCF_ERROR_NONE;
- int scf_ret;
- if (*exp_err != SCF_ERROR_NONE) {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_value_description() and expect an error\n");
- } else {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_value_description() and return the values "
- "common name\n");
- }
- scf_ret = scf_tmpl_value_description(p, locale, value, desc);
- scf_err = scf_error();
- if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
- /*
- * An error was expected check that the error returned
- * matches the expected error and report anomalies as
- * well as success.
- */
- if (scf_err != *exp_err) {
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_value_description() "
- "returned the wrong error\n\t"
- "EXPECTED: %d \n\t"
- "RETURNED: %d \n",
- (unsigned int)*exp_err, scf_ret);
- *exp_err = FAIL;
- } else {
- (void) fprintf(stdout, "--INFO: "
- "scf_tmpl_value_description() "
- "failed as expected\n");
- *exp_err = PASS;
- }
- } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
- /*
- * An error was expected but the template came back as
- * non-null which it should not have, therefore report
- * the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_value_description() did not fail as expected\n\t"
- "RETURNED: 0x%p\n", (void *)*desc);
- if (*desc)
- free(*desc);
- *exp_err = FAIL;
- } else if (scf_ret == -1) {
- /*
- * No error was expected, and template is still NULL
- * report the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_value_description() returned an error\n\t"
- "ERROR: %u (%s)\n",
- (unsigned int)scf_err, scf_strerror(scf_err));
- *exp_err = FAIL;
- } else if (*desc == NULL) {
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_value_description() did not "
- "fill in the desc pointer");
- *exp_err = FAIL;
- } else {
- *exp_err = PASS;
- }
- return (scf_ret);
- }
- /*
- * scftest_tmpl_value_in_constraint
- * Purpose: Call scf_tmpl_value_in_constraint()
- * Parameters:
- * input: scf_prop_tmpl_t *pt : a property pattern
- * scf_value_t *v : value
- * scf_tmpl_errors_t *errs: errors
- * scf_error_t *exp_err *err : the expected error
- * output: none
- * Returns: The result of the scf_tmpl_value_in_constraint call with PASS
- * or FAIL in the exp_err pointer.
- */
- int
- scftest_tmpl_value_in_constraint(const scf_prop_tmpl_t *pt, scf_value_t *v,
- scf_tmpl_errors_t **errs, scf_error_t *exp_err) {
- scf_error_t scf_err = SCF_ERROR_NONE;
- int scf_ret;
- if (*exp_err != SCF_ERROR_NONE) {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_value_in_constraint() "
- "and expect an error\n");
- } else {
- (void) fprintf(stdout, "--INFO: "
- "Call scf_tmpl_value_in_constraint() and return the "
- "value in constraint return value\n");
- }
- scf_ret = scf_tmpl_value_in_constraint(pt, v, errs);
- scf_err = scf_error();
- if (*exp_err != SCF_ERROR_NONE && scf_ret == -1) {
- /*
- * An error was expected check that the error returned
- * matches the expected error and report anomalies as
- * well as success.
- */
- if (scf_err != *exp_err) {
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_value_in_constraint() returned "
- "the wrong error\n\t"
- "EXPECTED: %u (%s)\n\t"
- "RETURNED: %u (%s)\n",
- (unsigned int)*exp_err, scf_strerror(*exp_err),
- (unsigned int)scf_err, scf_strerror(scf_err));
- *exp_err = FAIL;
- } else {
- (void) fprintf(stdout, "--INFO: "
- "scf_tmpl_value_in_constraint() "
- "failed as expected scf_ret = %d\n", scf_ret);
- *exp_err = PASS;
- }
- } else if (*exp_err != SCF_ERROR_NONE && scf_ret != -1) {
- /*
- * An error was expected but the template came back as
- * non-null which it should not have, therefore report
- * the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_value_in_constraint() did not "
- "fail as expected\n");
- *exp_err = FAIL;
- } else if (scf_ret == -1) {
- /*
- * No error was expected, and template is still NULL
- * report the anomaly.
- */
- (void) fprintf(stdout, "--DIAG: "
- "scf_tmpl_value_in_constraint() returned an error\n"
- "\tRETURNED: %d\n"
- "\tERROR: %u (%s)\n",
- scf_ret, (unsigned int)scf_err, scf_strerror(scf_err));
- *exp_err = FAIL;
- } else {
- if (scf_ret == 0) {
- *exp_err = PASS;
- (void) fprintf(stdout, "--INFO: "
- "scf_tmpl_value_in_constraint() found the value "
- "in the constraint\n");
- } else if (scf_ret == 1) {
- *exp_err = PASS;
- (void) fprintf(stdout, "--INFO: "
- "scf_tmpl_value_in_constraint() did not find the "
- "value in the constraint\n");
- } else {
- *exp_err = FAIL;
- (void) fprintf(stdout, "--INFO: "
- "scf_tmpl_value_in_constraint() returned an "
- "unexpected return value %d\n", scf_ret);
- }
- }
- return (scf_ret);
- }
- /*
- * verify_seps
- * Purpose :
- * Take an expected list of separators and verify that
- * each expected separator is represented in the separator
- * list.
- *
- * Parameters:
- * exp_seps : expected separtor list
- * seps : separator list
- * cnt : expected number of separators
- */
- int
- verify_seps(char *exp_seps, scf_values_t *seps, int cnt) {
- int *fnd;
- int i, j, ret = PASS;
- if (seps->values.v_astring == NULL) {
- (void) fprintf(stdout, "---DIAG: seps->values is NULL\n");
- if (cnt > 0) {
- ret = FAIL;
- }
- return (ret);
- }
- if ((fnd = malloc(sizeof (int) * cnt)) == NULL) {
- (void) fprintf(stdout, "--DIAG: malloc failed with %d\n",
- errno);
- ret = FAIL;
- return (ret);
- }
- bzero(fnd, sizeof (int) * cnt);
- for (i = 0; i < seps->value_count; i++) {
- for (j = 0; j < cnt; j++) {
- if ((char *)exp_seps[j] ==
- (char *)*seps->values.v_astring[i]) {
- if (fnd[j] == 0) {
- fnd[j] = 1;
- (void) fprintf(stdout, "--INFO: "
- "Found separator %c\n",
- *seps->values.v_astring[i]);
- break;
- }
- }
- }
- if (j == cnt) {
- ret = FAIL;
- (void) fprintf(stdout, "--DIAG: "
- "Did not find separator %c in expected list\n",
- *seps->values.v_astring[i]);
- }
- }
- if (i != cnt) {
- ret = FAIL;
- (void) fprintf(stdout, "--DIAG: "
- "Did not find all the separators in expected list\n");
- }
- free(fnd);
- return (ret);
- }
- /*
- * verify_constraint_names
- * Purpose :
- * Take a set of names and confirm that the names all exist
- * in the values set provided.
- *
- * Parameters :
- * exp_names : expected array of names (NULL terminated)
- * names : scf_values_t structure containing names to be checked
- */
- int
- verify_constraint_names(char **exp_names, scf_values_t *names) {
- char **constraints;
- int *fnd;
- int cnt, i, j, ret = PASS;
- cnt = 0;
- while (exp_names[cnt] != NULL)
- cnt++;
- i = 0;
- if ((fnd = malloc(sizeof (int) * cnt)) == NULL) {
- (void) fprintf(stdout, "--DIAG: malloc failed with %d\n",
- errno);
- ret = FAIL;
- return (ret);
- }
- bzero(fnd, sizeof (int) * cnt);
- constraints = names->values.v_astring;
- while (i < names->value_count != NULL) {
- for (j = 0; j < cnt; j++) {
- if (strcmp(constraints[i], exp_names[j]) == 0 &&
- fnd[j] == 0) {
- fnd[j] = 1;
- (void) fprintf(stdout, "--INFO: "
- "found constraint %s\n", constraints[i]);
- break;
- }
- }
- if (j == cnt) {
- ret = FAIL;
- (void) fprintf(stdout, "--DIAG: "
- "Did not find constraint %s in expected list\n",
- constraints[i]);
- }
- i++;
- }
- if (i != cnt) {
- ret = FAIL;
- (void) fprintf(stdout, "--DIAG: "
- "Did not find all the constraints in expected list\n");
- }
- free(fnd);
- return (ret);
- }
- /*
- * b32_convert
- * Purpose :
- * Convert a set of strings to base 32 values.
- *
- * Parameters :
- * vals : array of values.
- * nvals : pointer to an array of the new values
- * cnt : number of values to convert
- */
- int
- b32_convert(char **vals, char **nvals, int cnt) {
- FILE *fptr;
- char *b32c;
- char cmd[1024];
- char *buf;
- int i, cmdlen;
- if ((b32c = getenv("BASE32_CODE")) == NULL) {
- (void) fprintf(stdout, "--DIAG: "
- "scftest_tmpl_add_value() unable to get the\n"
- "base32 encoder environment variable\n");
- return (1);
- }
- for (i = 0; i < cnt; i++) {
- buf = malloc(SCFTEST_MAX_NAME_LENGTH);
- cmdlen = strlen(b32c) + strlen(vals[i]);
- if (cmdlen >= 1020) {
- (void) fprintf(stdout, "--DIAG: "
- "base 32 command is too long!\n"
- "%s -e %s\n", b32c, vals[i]);
- continue;
- }
- (void) snprintf(cmd, cmdlen + 5, "%s -e %s", b32c, vals[i]);
- fptr = popen(cmd, "r");
- (void) fgets(buf, SCFTEST_MAX_NAME_LENGTH, fptr);
- buf[strlen(buf) - 1] = '\0';
- (void) pclose(fptr);
- nvals[i] = buf;
- }
- return (0);
- }
- /*
- * scftest_tmpl_add_template
- * Purpose :
- * Take an array of value entries and turn them into
- * repository property group and property group entries,
- * that respresent a template entry.
- * Parameters:
- * svcname : pointer to the service name
- * instname : pointer to an instance name (optional)
- * pgname : pointer to the property group name
- * values : pointer to tmpl_values_t array
- * v_cnt : count of values
- * pg_flag : property group flag
- *
- */
- int
- scftest_tmpl_add_template(char *instance, scftest_name_t *pname, int pgorprop,
- tmpl_value_t values[], char **vallist, int vcnt, uint32_t pg_flag) {
- scf_propertygroup_t *pg;
- scf_handle_t *h;
- scf_service_t *s;
- scf_instance_t *i;
- scf_scope_t *c;
- scf_value_t ***v;
- scftest_name_t *prop_name;
- const char *scope, *svcname, *instname, *propertygroup, *property;
- char local[6 * REP_PROTOCOL_NAME_LEN];
- char *pgtype;
- int j, k, cnt, totalvs;
- int ret = 1;
- int *nvals;
- if (instance == NULL) {
- (void) fprintf(stdout, "--DIAG: "
- "scftest_tmpl_add_template() requires an\n"
- "instance name\n");
- goto out;
- }
- /* Create a connection handle */
- if ((h = scf_handle_create(SCF_VERSION)) == NULL) {
- (void) fprintf(stdout, "--DIAG: "
- "scf_handle_create() failed\n\t"
- "EXPECTED: handle != NULL, no error\n\t"
- "RETURNED: handle == NULL, %s\n",
- scf_strerror(scf_error()));
- goto out;
- } /* scf_handle_create() */
- /* Bind the handle to the repository */
- if (scf_handle_bind(h) != 0) {
- (void) fprintf(stdout, "--DIAG: "
- "Error connecting handle to repository: "
- "scf_handle_bind() failed\n\t"
- "EXPECTED: no error\n\t"
- "RETURNED: %s\n",
- scf_strerror(scf_error()));
- goto out;
- }
- if (scftest_create_local_scope(h, &c) != 0 || c == NULL) {
- (void) fprintf(stdout, "--DIAG: "
- "Error retrieving scope: "
- "scftest_handle_create_inited_scope() failed\n\t"
- "EXPECTED: no error\n\t"
- "RETURNED: %s\n",
- scf_strerror(scf_error()));
- goto out;
- }
- (void) strlcpy(local, instance, sizeof (local));
- (void) scf_parse_svc_fmri(local, &scope, &svcname, &instname,
- &propertygroup, &property);
- s = scftest_lookup_create_item(h, c, svcname, NULL, NULL, NULL);
- if (s == NULL) {
- (void) fprintf(stdout, "--INFO: Unable to get service %s\n",
- svcname);
- goto out;
- }
- i = scftest_lookup_create_item(h, c, svcname, instname, NULL, NULL);
- if (i == NULL) {
- (void) fprintf(stdout, "--INFO: Unable to get instance %s\n",
- instname);
- goto out;
- }
- if ((pgorprop & TMPL_NOADD) == 0) {
- if (pgorprop & TMPL_ADDPG) {
- pgtype = "template_pg_pattern";
- } else {
- pgtype = "template_prop_pattern";
- }
- /*
- * Add the property group (top level) repository entry,
- * and then get the property group representing the newly
- * added entry.
- */
- (void) scftest_instance_add_pgs(h, i, 1, pname, &pg_flag,
- pgtype);
- }
- pg = (scf_propertygroup_t *)scftest_lookup_create_item(h, c, svcname,
- instname, *pname, NULL);
- if (pg == NULL) {
- (void) fprintf(stdout, "--DIAG: The top level property group\n"
- "%s was not added to the repository correctly\n",
- (char *)pname);
- goto out;
- }
- /*
- * Total up the number of values to be added, and create the separate
- * value lists for each entry to the repository.
- */
- totalvs = 0;
- for (cnt = 0; cnt < vcnt; cnt++) {
- values[cnt].pval = malloc(sizeof (char *) * values[cnt].pcnt);
- for (j = totalvs, k = 0; j < totalvs + values[cnt].pcnt;
- j++, k++)
- values[cnt].pval[k] = vallist[j];
- totalvs = totalvs + values[cnt].pcnt;
- }
- /*
- * Allocate the needed memovry for the values to be stored into.
- */
- nvals = malloc(sizeof (int *) * vcnt);
- prop_name = malloc(sizeof (scftest_name_t) * vcnt);
- v = malloc(sizeof (scf_value_t *) * totalvs);
- if (nvals == NULL || prop_name == NULL || v == NULL) {
- (void) fprintf(stdout, "--DIAG: Unable to allocate the needed"
- "memory to create the scf values to be added to the"
- "repository\n");
- goto out;
- }
- /*
- * Walk the values creating the actual scf_value_t entries that
- * will be added to the repository.
- */
- for (cnt = 0; cnt < vcnt; cnt++) {
- nvals[cnt] = values[cnt].pcnt;
- (void) strcpy((char *)prop_name[cnt], values[cnt].pname);
- for (j = 0; j < values[cnt].pcnt; j++) {
- (&v[cnt])[j] = (scf_value_t **)scf_value_create(h);
- (void) scf_value_set_from_string((scf_value_t *)
- (&v[cnt])[j], values[cnt].ptype,
- values[cnt].pval[j]);
- }
- }
- (void) scftest_pg_add_properties_with_values(h, pg, vcnt, prop_name,
- nvals, (scf_value_t ***)v);
- /*
- * We have to refresh the instance so that the data is
- * available to the running instance.
- */
- (void) smf_refresh_instance(instance);
- free(nvals);
- free(prop_name);
- free(v);
- /*
- * This sleep in here, because it seems to take a few seconds for the
- * refresh to happen and the tests will come in before the refresh
- * complets. There is no way to make the refresh asynchronous at this
- * time. The only other way to handle this is to check for the value we
- * added but that's really what the test is doing. So we will give
- * it an amount of time for update to happen, and if the test is failing
- * due to ERR_NOT_FOUND then we know that we could be potentially racing
- * past this 5 second sleep.
- */
- (void) sleep(5);
- ret = 0;
- out :
- if (h)
- scf_handle_destroy(h);
- if (c)
- scf_scope_destroy(c);
- if (s)
- scf_service_destroy(s);
- if (i)
- scf_instance_destroy(i);
- return (ret);
- }
- /*
- * scftest_tmpl_add_value
- * Purpose :
- * Take an array of value entries and turn them into
- * repository property group and property group entries,
- * that respresent a value entry.
- * Parameters:
- * svcname : pointer to the service name
- * instname : pointer to an instance name (optional)
- * pname : pointer to the property name
- * values : pointer to tmpl_values_t array
- * vcnt : count of values
- * pg_flag : property group flag
- *
- */
- int
- /* ARGSUSED */
- scftest_tmpl_add_value(char *instance, scftest_name_t *pname,
- tmpl_value_t values[], char **vallist, int vcnt, uint32_t pg_flag) {
- scf_propertygroup_t *pg;
- scf_handle_t *h;
- scf_service_t *s;
- scf_instance_t *i;
- scf_scope_t *c;
- scf_value_t ***v;
- scftest_name_t *prop_name;
- const char *scope, *svcname, *instname, *propertygroup, *property;
- char local[6 * REP_PROTOCOL_NAME_LEN];
- int j, k, cnt, totalvs;
- int ret = 1;
- int *nvals;
- FILE *fptr;
- char *b32c;
- if ((b32c = getenv("BASE32_CODE")) == NULL) {
- (void) fprintf(stdout, "--DIAG: "
- "scftest_tmpl_add_value() unable to get the\n"
- "base32 encoder environment variable\n");
- goto out;
- }
- /* Create a connection handle */
- if ((h = scf_handle_create(SCF_VERSION)) == NULL) {
- (void) fprintf(stdout, "--DIAG: "
- "scf_handle_create() failed\n\t"
- "EXPECTED: handle != NULL, no error\n\t"
- "RETURNED: handle == NULL, %s\n",
- scf_strerror(scf_error()));
- goto out;
- } /* scf_handle_create() */
- /* Bind the handle to the repository */
- if (scf_handle_bind(h) != 0) {
- (void) fprintf(stdout, "--DIAG: "
- "Error connecting handle to repository: "
- "scf_handle_bind() failed\n\t"
- "EXPECTED: no error\n\t"
- "RETURNED: %s\n",
- scf_strerror(scf_error()));
- goto out;
- }
- if (scftest_create_local_scope(h, &c) != 0 || c == NULL) {
- (void) fprintf(stdout, "--DIAG: "
- "Error retrieving scope: "
- "scftest_handle_create_inited_scope() failed\n\t"
- "EXPECTED: no error\n\t"
- "RETURNED: %s\n",
- scf_strerror(scf_error()));
- goto out;
- }
- (void) strlcpy(local, instance, sizeof (local));
- (void) scf_parse_svc_fmri(local, &scope, &svcname, &instname,
- &propertygroup, &property);
- s = scftest_lookup_create_item(h, c, svcname, NULL, NULL, NULL);
- if (s == NULL) {
- (void) fprintf(stdout, "--INFO: Unable to get service %s\n",
- svcname);
- goto out;
- }
- i = scftest_lookup_create_item(h, c, svcname, instname, NULL, NULL);
- if (i == NULL) {
- (void) fprintf(stdout, "--INFO: Unable to get instance %s\n",
- instname);
- goto out;
- }
- pg = (scf_propertygroup_t *)scftest_lookup_create_item(h, c, svcname,
- instname, *pname, NULL);
- /*
- * Allocated the needed space and initialize the bits to create
- * the scf values to be added to the repository.
- */
- totalvs = 0;
- nvals = malloc(sizeof (int *) * vcnt);
- prop_name = malloc(sizeof (scftest_name_t) * vcnt);
- for (cnt = 0; cnt < vcnt; cnt++) {
- char buf[SCFTEST_MAX_NAME_LENGTH];
- char cmd[1024];
- int cmdlen, vlen;
- /*
- * Convert the pname to the base32 name that will be used
- * in the repository entry. This is coded to do this
- * work here, as there is no real reason to override this
- * value as any testing of this will just turn up as NOT_FOUND
- * errors, and can be simply tested outside of creating manual
- * entries in the repository.
- */
- cmdlen = strlen(b32c) + strlen(values[cnt].pname);
- if (cmdlen >= 1020) {
- (void) fprintf(stdout, "--DIAG: "
- "base 32 command is too long!\n"
- "%s -e %s\n", b32c, values[cnt].pname);
- goto out;
- }
- (void) snprintf(cmd, cmdlen + 5, "%s -e %s", b32c,
- values[cnt].pname);
- fptr = popen(cmd, "r");
- (void) fgets(buf, SCFTEST_MAX_NAME_LENGTH, fptr);
- buf[strlen(buf) - 1] = '\0';
- vlen = strlen(buf) + strlen(vallist[totalvs]);
- if (vlen >= SCFTEST_MAX_NAME_LENGTH) {
- (void) fprintf(stdout, "--DIAG: "
- "prop name value is too long!\n"
- "value_%s%s\n", buf, vallist[totalvs]);
- goto out;
- }
- (void) snprintf((char *)prop_name[cnt], vlen + 7, "value_%s%s",
- buf, vallist[totalvs]);
- (void) pclose(fptr);
- totalvs++;
- (void) fprintf(stdout, "prop_name[%d] = %s\n",
- cnt, prop_name[cnt]);
- /*
- * Initialize the pvals portion of the values structure
- * with the values in the list. Here we set the pcnt back by
- * 1 to account for the postfix of the prop_name value.
- */
- values[cnt].pval = malloc(sizeof (char *) *
- values[cnt].pcnt - 1);
- for (j = totalvs, k = 0;
- j < totalvs + (values[cnt].pcnt - 1); j++, k++)
- values[cnt].pval[k] = vallist[j];
- totalvs = totalvs + (values[cnt].pcnt - 1);
- }
- /*
- * Allocate the memory the the scf values themselves.
- */
- v = malloc(sizeof (scf_value_t *) * totalvs);
- /*
- * Note : the pcnt is decremented by 1 here, to account for the
- * postfix of the prop_name that is part of the value list.
- */
- for (cnt = 0; cnt < vcnt; cnt++) {
- nvals[cnt] = values[cnt].pcnt - 1;
- for (j = 0; j < values[cnt].pcnt - 1; j++) {
- (&v[cnt])[j] = (scf_value_t **)scf_value_create(h);
- (void) scf_value_set_from_string((scf_value_t *)
- (&v[cnt])[j], values[cnt].ptype,
- values[cnt].pval[j]);
- }
- }
- (void) scftest_pg_add_properties_with_values(h, pg, vcnt, prop_name,
- nvals, (scf_value_t ***)v);
- (void) smf_refresh_instance(instance);
- /*
- * This sleep in here, because it seems to take a few seconds for the
- * refresh to happen and the tests get will come in before the refresh
- * complets. There is no way to make the refresh asynchronous at this
- * time. The only other way to handle this is to check for the value we
- * added but that's really what the test is doing. So we will give
- * it an amount of time for update to happen, and if the test is failing
- * due to ERR_NOT_FOUND then we know that we could be potentially racing
- */
- (void) sleep(5);
- ret = 0;
- out :
- if (h)
- scf_handle_destroy(h);
- if (c)
- scf_scope_destroy(c);
- if (s)
- scf_service_destroy(s);
- if (i)
- scf_instance_destroy(i);
- return (ret);
- }
- /*
- * scftest_tmpl_del_template_pg
- * Purpose :
- * Take a property group and remove it from the repository.
- *
- * Parameters:
- * svcname : pointer to the service name
- * instname : pointer to an instance name (optional)
- * pname : pointer to the property group name
- */
- int
- scftest_tmpl_del_template_pg(char *instance, scftest_name_t *pname) {
- scf_handle_t *h;
- scf_service_t *s;
- scf_instance_t *i;
- scf_scope_t *c;
- const char *scope, *svcname, *instname, *propertygroup, *property;
- char local[6 * REP_PROTOCOL_NAME_LEN];
- int ret = 0;
- /* Create a connection handle */
- if ((h = scf_handle_create(SCF_VERSION)) == NULL) {
- (void) fprintf(stdout, "--DIAG: "
- "scf_handle_create() failed\n\t"
- "EXPECTED: handle != NULL, no error\n\t"
- "RETURNED: handle == NULL, %s\n",
- scf_strerror(scf_error()));
- ret = 1;
- goto out;
- }
- /* Bind the handle to the repository */
- if (scf_handle_bind(h) != 0) {
- (void) fprintf(stdout, "--DIAG: "
- "Error connecting handle to repository: "
- "scf_handle_bind() failed\n\t"
- "EXPECTED: no error\n\t"
- "RETURNED: %s\n",
- scf_strerror(scf_error()));
- ret = 1;
- goto out;
- }
- if (scftest_create_local_scope(h, &c) != 0 || c == NULL) {
- (void) fprintf(stdout, "--DIAG: "
- "Error retrieving scope: "
- "scftest_handle_create_inited_scope() failed\n\t"
- "EXPECTED: no error\n\t"
- "RETURNED: %s\n",
- scf_strerror(scf_error()));
- ret = 1;
- goto out;
- }
- (void) strlcpy(local, instance, sizeof (local));
- (void) scf_parse_svc_fmri(local, &scope, &svcname, &instname,
- &propertygroup, &property);
- if ((s = scftest_get_service(h, c, svcname)) == NULL) {
- (void) fprintf(stdout, "--DIAG: "
- "Error looking up service '%s': "
- "scftest_get_service() failed\n\t"
- "EXPECTED: no error\n\t"
- "RETURNED: %s\n",
- svcname, scf_strerror(scf_error()));
- ret = 1;
- goto out;
- }
- if ((i = scftest_get_instance(h, c, svcname, instname)) == NULL) {
- (void) fprintf(stdout, "--DIAG: "
- "Error looking up instance '%s': "
- "scftest_get_service() failed\n\t"
- "EXPECTED: no error\n\t"
- "RETURNED: %s\n",
- svcname, scf_strerror(scf_error()));
- ret = 1;
- goto out;
- }
- (void) scftest_instance_delete_pgs(h, i, 1, pname);
- out :
- if (h)
- scf_handle_destroy(h);
- if (c)
- scf_scope_destroy(c);
- if (s)
- scf_service_destroy(s);
- if (i)
- scf_instance_destroy(i);
- return (ret);
- }