caqltest.c 5.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213

#include "postgres.h"
#include "miscadmin.h"
#include "cdb/cdbtm.h"
#include "cdb/cdbutil.h"
#include "cdb/cdbvars.h"
#include "commands/queue.h"
#include "executor/spi.h"
#include "postmaster/fts.h"
#include "utils/builtins.h"
#include "utils/lsyscache.h"
#include "utils/rel.h"

/* tests for caql coverage in regproc.c */
extern Datum caql_bootstrap_regproc(PG_FUNCTION_ARGS);

/* tests for caql coverage in lsyscache.c */
extern Datum check_get_atttypmod(PG_FUNCTION_ARGS);
extern Datum check_get_opname(PG_FUNCTION_ARGS);
extern Datum check_get_typ_typrelid(PG_FUNCTION_ARGS);
extern Datum check_get_base_element_type(PG_FUNCTION_ARGS);

/* test for caql coverage in spi.c */
extern Datum check_SPI_gettype(PG_FUNCTION_ARGS);

/* tests for caql coverage in cdbutil.c */
extern Datum check_master_standby_dbid(PG_FUNCTION_ARGS);
extern Datum check_my_mirror_dbid(PG_FUNCTION_ARGS);
extern Datum check_dbid_get_dbinfo(PG_FUNCTION_ARGS);
extern Datum check_contentid_get_dbid(PG_FUNCTION_ARGS);

/* tests for caql coverage in segadmin.c */
extern Datum check_gp_activate_standby(PG_FUNCTION_ARGS);

/* tests for caql coverage in queue.c */
extern Datum check_GetResqueueName(PG_FUNCTION_ARGS);

PG_FUNCTION_INFO_V1(caql_bootstrap_regproc);
Datum
caql_bootstrap_regproc(PG_FUNCTION_ARGS)
{
	char	   *cstr_regprocin = "boolin";
	char	   *cstr_regoperin = "#>="; /* we should pick up a unique name */
	char	   *cstr_regclassin = "pg_class";
	char	   *cstr_regtypein = "bool";
	Datum		result;
	StringInfoData	buf;

	initStringInfo(&buf);

	SetProcessingMode(BootstrapProcessing);
	/* regproc */
	result = DirectFunctionCall1(regprocin, CStringGetDatum(cstr_regprocin));
	appendStringInfo(&buf, "regprocin(%s) = %d\n",
			cstr_regprocin, DatumGetObjectId(result));

	/* regoper */
	result = DirectFunctionCall1(regoperin, CStringGetDatum(cstr_regoperin));
	appendStringInfo(&buf, "regoperin(%s) = %d\n",
			cstr_regoperin, DatumGetObjectId(result));

	/* regclass */
	result = DirectFunctionCall1(regclassin, CStringGetDatum(cstr_regclassin));
	appendStringInfo(&buf, "regclassin(%s) = %d\n",
			cstr_regclassin, DatumGetObjectId(result));

	/* regtype */
	result = DirectFunctionCall1(regtypein, CStringGetDatum(cstr_regtypein));
	appendStringInfo(&buf, "regtypein(%s) = %d\n",
			cstr_regtypein, DatumGetObjectId(result));
	SetProcessingMode(NormalProcessing);

	PG_RETURN_TEXT_P(cstring_to_text(buf.data));
}

/*
 * Testing caql coverage for lsyscache.c-
 */
PG_FUNCTION_INFO_V1(check_get_atttypmod);
Datum
check_get_atttypmod(PG_FUNCTION_ARGS)
{
	Oid relid = PG_GETARG_OID(0);
	AttrNumber attnum = PG_GETARG_INT16(1);
	int32 result;

	result = get_atttypmod(relid, attnum);

	PG_RETURN_INT32(result);
}

PG_FUNCTION_INFO_V1(check_get_opname);
Datum
check_get_opname(PG_FUNCTION_ARGS)
{
	Oid opno = PG_GETARG_OID(0);
	char *result;
	StringInfoData buf; 

	initStringInfo(&buf); 
	result = get_opname(opno);
	if (result)
		appendStringInfo(&buf, "%s", result);

	PG_RETURN_TEXT_P(cstring_to_text(buf.data));
}

PG_FUNCTION_INFO_V1(check_get_typ_typrelid);
Datum
check_get_typ_typrelid(PG_FUNCTION_ARGS)
{
	Oid typid = PG_GETARG_OID(0);
	Oid result;

	result = get_typ_typrelid(typid);

	PG_RETURN_OID(result);
}

PG_FUNCTION_INFO_V1(check_get_base_element_type);
Datum
check_get_base_element_type(PG_FUNCTION_ARGS)
{
	Oid typid = PG_GETARG_OID(0);
	Oid result;

	result = get_base_element_type(typid);

	PG_RETURN_OID(result);
}

PG_FUNCTION_INFO_V1(check_SPI_gettype);
Datum
check_SPI_gettype(PG_FUNCTION_ARGS)
{
	int		fnumber = PG_GETARG_INT32(0);
	Relation	rel = relation_open(RelationRelationId, AccessShareLock);
	char		*name = SPI_gettype(RelationGetDescr(rel), fnumber);
	relation_close(rel, AccessShareLock);

	PG_RETURN_TEXT_P(cstring_to_text(name));
}

PG_FUNCTION_INFO_V1(check_master_standby_dbid);
Datum
check_master_standby_dbid(PG_FUNCTION_ARGS)
{
	int result;
	result = master_standby_dbid();

	PG_RETURN_OID(result);
}

PG_FUNCTION_INFO_V1(check_my_mirror_dbid);
Datum
check_my_mirror_dbid(PG_FUNCTION_ARGS)
{
	int result;
	result = my_mirror_dbid();

	PG_RETURN_OID(result);
}

PG_FUNCTION_INFO_V1(check_dbid_get_dbinfo);
Datum
check_dbid_get_dbinfo(PG_FUNCTION_ARGS)
{
	int16 result;
	int dbid = PG_GETARG_INT16(0);
	CdbComponentDatabaseInfo *i = NULL;

	i = dbid_get_dbinfo(dbid);

	result = i->dbid;

	PG_RETURN_INT16(result);
}

PG_FUNCTION_INFO_V1(check_contentid_get_dbid);
Datum
check_contentid_get_dbid(PG_FUNCTION_ARGS)
{
	int16 contentid = PG_GETARG_INT16(0);
	char role = PG_GETARG_CHAR(1);
	bool getPreferredRoleNotCurrentRole = PG_GETARG_BOOL(2);
	int16 result;

	result = contentid_get_dbid(contentid, role, getPreferredRoleNotCurrentRole);

	PG_RETURN_INT16(result);
}

PG_FUNCTION_INFO_V1(check_gp_activate_standby);
Datum
check_gp_activate_standby(PG_FUNCTION_ARGS)
{
	/* Pretend as if I'm a standby.  The dbid is given as an argument. */
	GpIdentity.dbid = PG_GETARG_INT16(0);

	/* There is no DirectFunctionCall0 */
	DirectFunctionCall1(gp_activate_standby, Int32GetDatum(0));

	PG_RETURN_NULL();
}

PG_FUNCTION_INFO_V1(check_GetResqueueName);
Datum
check_GetResqueueName(PG_FUNCTION_ARGS)
{
	Oid		resqueueOid = PG_GETARG_OID(0);

	PG_RETURN_TEXT_P(cstring_to_text(GetResqueueName(resqueueOid)));
}