commit last state
[ppam-mpi.git] / code / test / MPI_Communication / t.pack.c
CommitLineData
81923e5c
BA
1#include "lut.h"
2#include <stdlib.h>
3#include "MPI_Communication/pack.h"
4#include "Util/types.h"
5#include <stdint.h>
6#include "Util/utils.h"
7
8// Work_t
9void t_pack1()
10{
11 Work_t* work = (Work_t*)malloc(sizeof(Work_t));
12 work->inputFileName = "../data/inputTest.bin";
13 work->nbSeries = 5;
14 uint32_t ranks[] =
15 {
16 0,
17 12*65536 + 3*256+11,
18 32*16777216 + 2*65536 + 17*256 + 42,
19 123,
20 51*16777216 + 77*65536 + 0*256 + 10
21 };
22 work->ranks = ranks;
23 work->nbClusters = 15;
24 work->clustOnMedoids = 0;
25 work->p_for_dissims = 1;
26
27 // Hard-coded expected packed work
28 unsigned char expectedPackedWork[] =
29 {
30 // --> ../data/inputTest.bin
31 46,46,47,100,97,116,97,47,105,110,112,117,116,84,101,115,116,46,98,105,110,
32 // continue with 256 - strlen("../data/inputTest.bin") zeros...
33 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
34 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
35 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
36 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
37 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
38 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
39 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
40 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
41 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
42 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
43 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
44 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
45 // --> 5, {ranks}+0,0, 15, 0 on 4-bytes integers little-endian
46 5,0,0,0, 0,0,0,0, 11,3,12,0, 42,17,2,32, 123,0,0,0, 10,0,77,51, 0,0,0,0, 0,0,0,0,
47 15,0,0,0, 0,0,0,0, 1,0,0,0
48 };
49
50 uint32_t nbSeriesInChunk = 7;
51 uint32_t work_message_length = get_packedWork_length(nbSeriesInChunk);
52 unsigned char packedWork[work_message_length];
53 pack_work(work, nbSeriesInChunk, packedWork);
54
55 for (uint32_t i=0; i<work_message_length; i++)
56 {
57 LUT_ASSERT(packedWork[i] == expectedPackedWork[i]);
58 }
59
60 free(work);
61}
62
63// Result_t
64void t_pack2() {
65
66 Result_t* result = (Result_t*)malloc(sizeof(Result_t));
67 uint32_t nbClusters = result->nbClusters = 5;
68 uint32_t medoids_ID[] =
69 {
70 15*65536 + 13*256+11,
71 11,
72 17*16777216 + 0*65536 + 14*256 + 42,
73 123*65536 + 0*256 + 7,
74 51*16777216 + 0*65536 + 0*256 + 10
75 };
76 result->medoids_ID = medoids_ID;
77 uint32_t medoids_ranks[] =
78 {
79 5*65536 + 32,
80 11*256 + 4,
81 23*16777216 + 42,
82 35*65536 + 5*256 + 77,
83 1*16777216 + 1*65536 + 1*256 + 10
84 };
85 result->medoids_ranks = medoids_ranks;
86
87 // Hard-coded expected result
88 unsigned char expectedPackedResult[] =
89 {
90 // 5, {medoids_ID}, {medoids_ranks}
91 5,0,0,0,
92 11,13,15,0, 11,0,0,0, 42,14,0,17, 7,0,123,0, 10,0,0,51,
93 32,0,5,0, 4,11,0,0, 42,0,0,23, 77,5,35,0, 10,1,1,1
94 };
95
96 uint32_t result_message_length = get_packedResult_length(nbClusters);
97 unsigned char packedResult[result_message_length];
98 pack_result(result, packedResult);
99
100 for (uint32_t i=0; i<result_message_length; i++)
101 {
102 LUT_ASSERT(packedResult[i] == expectedPackedResult[i]);
103 }
104
105 free(result);
106}