exporting_doubles.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. #include "test_exporting_engine.h"
  3. struct engine *__real_read_exporting_config();
  4. struct engine *__wrap_read_exporting_config()
  5. {
  6. function_called();
  7. return mock_ptr_type(struct engine *);
  8. }
  9. struct engine *__mock_read_exporting_config()
  10. {
  11. struct engine *engine = calloc(1, sizeof(struct engine));
  12. engine->config.hostname = strdupz("test_engine_host");
  13. engine->config.update_every = 3;
  14. engine->instance_root = calloc(1, sizeof(struct instance));
  15. struct instance *instance = engine->instance_root;
  16. instance->engine = engine;
  17. instance->config.type = EXPORTING_CONNECTOR_TYPE_GRAPHITE;
  18. instance->config.name = strdupz("instance_name");
  19. instance->config.destination = strdupz("localhost");
  20. instance->config.username = strdupz("");
  21. instance->config.password = strdupz("");
  22. instance->config.prefix = strdupz("netdata");
  23. instance->config.hostname = strdupz("test-host");
  24. instance->config.update_every = 1;
  25. instance->config.buffer_on_failures = 10;
  26. instance->config.timeoutms = 10000;
  27. instance->config.charts_pattern = simple_pattern_create("*", NULL, SIMPLE_PATTERN_EXACT);
  28. instance->config.hosts_pattern = simple_pattern_create("*", NULL, SIMPLE_PATTERN_EXACT);
  29. instance->config.options = EXPORTING_SOURCE_DATA_AS_COLLECTED | EXPORTING_OPTION_SEND_NAMES;
  30. return engine;
  31. }
  32. int __real_init_connectors(struct engine *engine);
  33. int __wrap_init_connectors(struct engine *engine)
  34. {
  35. function_called();
  36. check_expected_ptr(engine);
  37. return mock_type(int);
  38. }
  39. int __real_mark_scheduled_instances(struct engine *engine);
  40. int __wrap_mark_scheduled_instances(struct engine *engine)
  41. {
  42. function_called();
  43. check_expected_ptr(engine);
  44. return mock_type(int);
  45. }
  46. calculated_number __real_exporting_calculate_value_from_stored_data(
  47. struct instance *instance,
  48. RRDDIM *rd,
  49. time_t *last_timestamp);
  50. calculated_number __wrap_exporting_calculate_value_from_stored_data(
  51. struct instance *instance,
  52. RRDDIM *rd,
  53. time_t *last_timestamp)
  54. {
  55. (void)instance;
  56. (void)rd;
  57. *last_timestamp = 15052;
  58. function_called();
  59. return mock_type(calculated_number);
  60. }
  61. int __real_prepare_buffers(struct engine *engine);
  62. int __wrap_prepare_buffers(struct engine *engine)
  63. {
  64. function_called();
  65. check_expected_ptr(engine);
  66. return mock_type(int);
  67. }
  68. void __wrap_create_main_rusage_chart(RRDSET **st_rusage, RRDDIM **rd_user, RRDDIM **rd_system)
  69. {
  70. function_called();
  71. check_expected_ptr(st_rusage);
  72. check_expected_ptr(rd_user);
  73. check_expected_ptr(rd_system);
  74. }
  75. void __wrap_send_main_rusage(RRDSET *st_rusage, RRDDIM *rd_user, RRDDIM *rd_system)
  76. {
  77. function_called();
  78. check_expected_ptr(st_rusage);
  79. check_expected_ptr(rd_user);
  80. check_expected_ptr(rd_system);
  81. }
  82. int __wrap_send_internal_metrics(struct instance *instance)
  83. {
  84. function_called();
  85. check_expected_ptr(instance);
  86. return mock_type(int);
  87. }
  88. int __wrap_rrdhost_is_exportable(struct instance *instance, RRDHOST *host)
  89. {
  90. function_called();
  91. check_expected_ptr(instance);
  92. check_expected_ptr(host);
  93. return mock_type(int);
  94. }
  95. int __wrap_rrdset_is_exportable(struct instance *instance, RRDSET *st)
  96. {
  97. function_called();
  98. check_expected_ptr(instance);
  99. check_expected_ptr(st);
  100. return mock_type(int);
  101. }
  102. int __mock_start_batch_formatting(struct instance *instance)
  103. {
  104. function_called();
  105. check_expected_ptr(instance);
  106. return mock_type(int);
  107. }
  108. int __mock_start_host_formatting(struct instance *instance, RRDHOST *host)
  109. {
  110. function_called();
  111. check_expected_ptr(instance);
  112. check_expected_ptr(host);
  113. return mock_type(int);
  114. }
  115. int __mock_start_chart_formatting(struct instance *instance, RRDSET *st)
  116. {
  117. function_called();
  118. check_expected_ptr(instance);
  119. check_expected_ptr(st);
  120. return mock_type(int);
  121. }
  122. int __mock_metric_formatting(struct instance *instance, RRDDIM *rd)
  123. {
  124. function_called();
  125. check_expected_ptr(instance);
  126. check_expected_ptr(rd);
  127. return mock_type(int);
  128. }
  129. int __mock_end_chart_formatting(struct instance *instance, RRDSET *st)
  130. {
  131. function_called();
  132. check_expected_ptr(instance);
  133. check_expected_ptr(st);
  134. return mock_type(int);
  135. }
  136. int __mock_end_host_formatting(struct instance *instance, RRDHOST *host)
  137. {
  138. function_called();
  139. check_expected_ptr(instance);
  140. check_expected_ptr(host);
  141. return mock_type(int);
  142. }
  143. int __mock_end_batch_formatting(struct instance *instance)
  144. {
  145. function_called();
  146. check_expected_ptr(instance);
  147. return mock_type(int);
  148. }
  149. int __wrap_simple_connector_end_batch(struct instance *instance)
  150. {
  151. function_called();
  152. check_expected_ptr(instance);
  153. return mock_type(int);
  154. }
  155. #if ENABLE_PROMETHEUS_REMOTE_WRITE
  156. void *__wrap_init_write_request()
  157. {
  158. function_called();
  159. return mock_ptr_type(void *);
  160. }
  161. void __wrap_add_host_info(
  162. void *write_request_p,
  163. const char *name, const char *instance, const char *application, const char *version, const int64_t timestamp)
  164. {
  165. function_called();
  166. check_expected_ptr(write_request_p);
  167. check_expected_ptr(name);
  168. check_expected_ptr(instance);
  169. check_expected_ptr(application);
  170. check_expected_ptr(version);
  171. check_expected(timestamp);
  172. }
  173. void __wrap_add_label(void *write_request_p, char *key, char *value)
  174. {
  175. function_called();
  176. check_expected_ptr(write_request_p);
  177. check_expected_ptr(key);
  178. check_expected_ptr(value);
  179. }
  180. void __wrap_add_metric(
  181. void *write_request_p,
  182. const char *name, const char *chart, const char *family, const char *dimension,
  183. const char *instance, const double value, const int64_t timestamp)
  184. {
  185. function_called();
  186. check_expected_ptr(write_request_p);
  187. check_expected_ptr(name);
  188. check_expected_ptr(chart);
  189. check_expected_ptr(family);
  190. check_expected_ptr(dimension);
  191. check_expected_ptr(instance);
  192. check_expected(value);
  193. check_expected(timestamp);
  194. }
  195. #endif // ENABLE_PROMETHEUS_REMOTE_WRITE
  196. #if HAVE_KINESIS
  197. void __wrap_aws_sdk_init()
  198. {
  199. function_called();
  200. }
  201. void __wrap_kinesis_init(
  202. void *kinesis_specific_data_p, const char *region, const char *access_key_id, const char *secret_key,
  203. const long timeout)
  204. {
  205. function_called();
  206. check_expected_ptr(kinesis_specific_data_p);
  207. check_expected_ptr(region);
  208. check_expected_ptr(access_key_id);
  209. check_expected_ptr(secret_key);
  210. check_expected(timeout);
  211. }
  212. void __wrap_kinesis_put_record(
  213. void *kinesis_specific_data_p, const char *stream_name, const char *partition_key, const char *data,
  214. size_t data_len)
  215. {
  216. function_called();
  217. check_expected_ptr(kinesis_specific_data_p);
  218. check_expected_ptr(stream_name);
  219. check_expected_ptr(partition_key);
  220. check_expected_ptr(data);
  221. check_expected_ptr(data);
  222. check_expected(data_len);
  223. }
  224. int __wrap_kinesis_get_result(void *request_outcomes_p, char *error_message, size_t *sent_bytes, size_t *lost_bytes)
  225. {
  226. function_called();
  227. check_expected_ptr(request_outcomes_p);
  228. check_expected_ptr(error_message);
  229. check_expected_ptr(sent_bytes);
  230. check_expected_ptr(lost_bytes);
  231. return mock_type(int);
  232. }
  233. #endif // HAVE_KINESIS
  234. #if ENABLE_EXPORTING_PUBSUB
  235. int __wrap_pubsub_init(
  236. void *pubsub_specific_data_p, char *error_message, const char *destination, const char *credentials_file,
  237. const char *project_id, const char *topic_id)
  238. {
  239. function_called();
  240. check_expected_ptr(pubsub_specific_data_p);
  241. check_expected_ptr(error_message);
  242. check_expected_ptr(destination);
  243. check_expected_ptr(credentials_file);
  244. check_expected_ptr(project_id);
  245. check_expected_ptr(topic_id);
  246. return mock_type(int);
  247. }
  248. int __wrap_pubsub_add_message(void *pubsub_specific_data_p, char *data)
  249. {
  250. function_called();
  251. check_expected_ptr(pubsub_specific_data_p);
  252. check_expected_ptr(data);
  253. return mock_type(int);
  254. }
  255. int __wrap_pubsub_publish(
  256. void *pubsub_specific_data_p, char *error_message, size_t buffered_metrics, size_t buffered_bytes)
  257. {
  258. function_called();
  259. check_expected_ptr(pubsub_specific_data_p);
  260. check_expected_ptr(error_message);
  261. check_expected(buffered_metrics);
  262. check_expected(buffered_bytes);
  263. return mock_type(int);
  264. }
  265. int __wrap_pubsub_get_result(
  266. void *pubsub_specific_data_p, char *error_message,
  267. size_t *sent_metrics, size_t *sent_bytes, size_t *lost_metrics, size_t *lost_bytes)
  268. {
  269. function_called();
  270. check_expected_ptr(pubsub_specific_data_p);
  271. check_expected_ptr(error_message);
  272. check_expected_ptr(sent_metrics);
  273. check_expected_ptr(sent_bytes);
  274. check_expected_ptr(lost_metrics);
  275. check_expected_ptr(lost_bytes);
  276. return mock_type(int);
  277. }
  278. #endif // ENABLE_EXPORTING_PUBSUB
  279. #if HAVE_MONGOC
  280. void __wrap_mongoc_init()
  281. {
  282. function_called();
  283. }
  284. mongoc_uri_t * __wrap_mongoc_uri_new_with_error (const char *uri_string, bson_error_t *error)
  285. {
  286. function_called();
  287. check_expected_ptr(uri_string);
  288. check_expected_ptr(error);
  289. return mock_ptr_type(mongoc_uri_t *);
  290. }
  291. int32_t __wrap_mongoc_uri_get_option_as_int32(const mongoc_uri_t *uri, const char *option, int32_t fallback)
  292. {
  293. function_called();
  294. check_expected_ptr(uri);
  295. check_expected_ptr(option);
  296. check_expected(fallback);
  297. return mock_type(int32_t);
  298. }
  299. bool __wrap_mongoc_uri_set_option_as_int32 (const mongoc_uri_t *uri, const char *option, int32_t value)
  300. {
  301. function_called();
  302. check_expected_ptr(uri);
  303. check_expected_ptr(option);
  304. check_expected(value);
  305. return mock_type(bool);
  306. }
  307. mongoc_client_t * __wrap_mongoc_client_new_from_uri (const mongoc_uri_t *uri)
  308. {
  309. function_called();
  310. check_expected_ptr(uri);
  311. return mock_ptr_type(mongoc_client_t *);
  312. }
  313. bool __wrap_mongoc_client_set_appname (mongoc_client_t *client, const char *appname)
  314. {
  315. function_called();
  316. check_expected_ptr(client);
  317. check_expected_ptr(appname);
  318. return mock_type(bool);
  319. }
  320. mongoc_collection_t *
  321. __wrap_mongoc_client_get_collection(mongoc_client_t *client, const char *db, const char *collection)
  322. {
  323. function_called();
  324. check_expected_ptr(client);
  325. check_expected_ptr(db);
  326. check_expected_ptr(collection);
  327. return mock_ptr_type(mongoc_collection_t *);
  328. }
  329. void __wrap_mongoc_uri_destroy (mongoc_uri_t *uri)
  330. {
  331. function_called();
  332. check_expected_ptr(uri);
  333. }
  334. bool __wrap_mongoc_collection_insert_many(
  335. mongoc_collection_t *collection,
  336. const bson_t **documents,
  337. size_t n_documents,
  338. const bson_t *opts,
  339. bson_t *reply,
  340. bson_error_t *error)
  341. {
  342. function_called();
  343. check_expected_ptr(collection);
  344. check_expected_ptr(documents);
  345. check_expected(n_documents);
  346. check_expected_ptr(opts);
  347. check_expected_ptr(reply);
  348. check_expected_ptr(error);
  349. return mock_type(bool);
  350. }
  351. #endif // HAVE_MONGOC