示例#1
0
Ivector	vpack			(Fvector src)
{
	Fvector			_v;
	int	bx			= fpack	(src.x);
	int by			= fpack	(src.y);
	int bz			= fpackZ(src.z);
	// dumb test
	float	e_best	= flt_max;
	int		r=bx,g=by,b=bz;
#ifdef DEBUG
	int		d=0;
#else
	int		d=3;
#endif
	for (int x=_max(bx-d,0); x<=_min(bx+d,255); x++)
	for (int y=_max(by-d,0); y<=_min(by+d,255); y++)
	for (int z=_max(bz-d,0); z<=_min(bz+d,255); z++)
	{
		_v				= vunpack(x,y,z);
		float	m		= _v.magnitude();
		float	me		= _abs(m-1.f);
		if	(me>0.03f)	continue;
		_v.div	(m);
		float	e		= _abs(src.dotproduct(_v)-1.f);
		if (e<e_best)	{
			e_best		= e;
			r=x,g=y,b=z;
		}
	}
	Ivector		ipck;
	ipck.set	(r,g,b);
	return		ipck;
}
示例#2
0
TEST_F(PacksTests, test_check_version) {
  Pack zpack("fake_version_pack", getPackWithFakeVersion());
  EXPECT_FALSE(zpack.checkVersion());

  Pack fpack("discovery_pack", getPackWithDiscovery());
  EXPECT_TRUE(fpack.checkVersion());
}
示例#3
0
TEST_F(PacksTests, test_check_platform) {
  Pack fpack("discovery_pack", getPackWithDiscovery());
  EXPECT_TRUE(fpack.checkPlatform());

  // Depending on the current build platform, this check will be true or false.
  fpack.platform_ = kSDKPlatform;
  EXPECT_TRUE(fpack.checkPlatform());

  fpack.platform_ = (kSDKPlatform == "darwin") ? "linux" : "darwin";
  EXPECT_FALSE(fpack.checkPlatform());

  fpack.platform_ = "null";
  EXPECT_TRUE(fpack.checkPlatform());

  fpack.platform_ = "";
  EXPECT_TRUE(fpack.checkPlatform());

  fpack.platform_ = "bad_value";
  EXPECT_FALSE(fpack.checkPlatform());

  fpack.platform_ = "posix";
  if (isPlatform(PlatformType::TYPE_POSIX) ||
      isPlatform(PlatformType::TYPE_LINUX) ||
      isPlatform(PlatformType::TYPE_OSX) ||
      isPlatform(PlatformType::TYPE_FREEBSD)) {
    EXPECT_TRUE(fpack.checkPlatform());
  }

  if (isPlatform(PlatformType::TYPE_WINDOWS)) {
    EXPECT_FALSE(fpack.checkPlatform());
  }
}
示例#4
0
void fincr(_MIPD_ flash x,int n,int d,flash y)
{ /* increment x by small fraction n/d - y=x+(n/d) */
#ifdef MR_OS_THREADS
    miracl *mr_mip=get_mip();
#endif
    if (mr_mip->ERNUM) return;

    MR_IN(43)

    if (d<0)
    {
        d=(-d);
        n=(-n);
    }
    numer(_MIPP_ x,mr_mip->w1);
    denom(_MIPP_ x,mr_mip->w2);
    mr_mip->check=OFF;
    premult(_MIPP_ mr_mip->w1,d,mr_mip->w5);
    premult(_MIPP_ mr_mip->w2,d,mr_mip->w6);
    premult(_MIPP_ mr_mip->w2,n,mr_mip->w0);
    add(_MIPP_ mr_mip->w5,mr_mip->w0,mr_mip->w5);
    mr_mip->check=ON;
    if (d==1 && fit(mr_mip->w5,mr_mip->w6,mr_mip->nib))
        fpack(_MIPP_ mr_mip->w5,mr_mip->w6,y);
    else
        mround(_MIPP_ mr_mip->w5,mr_mip->w6,y);
    MR_OUT
}
示例#5
0
TEST_F(PacksTests, test_should_pack_execute) {
  Pack kpack("unrestricted_pack", getUnrestrictedPack());
  EXPECT_TRUE(kpack.shouldPackExecute());

  Pack fpack("discovery_pack", getPackWithDiscovery());
  EXPECT_FALSE(fpack.shouldPackExecute());
}
示例#6
0
TEST_F(PacksTests, test_get_discovery_queries) {
  std::vector<std::string> expected;

  Pack kpack("unrestricted_pack", getUnrestrictedPack());
  EXPECT_EQ(kpack.getDiscoveryQueries(), expected);

  expected = {"select pid from processes where name = 'foobar';"};
  Pack fpack("discovery_pack", getPackWithDiscovery());
  EXPECT_EQ(fpack.getDiscoveryQueries(), expected);
}
示例#7
0
TEST_F(PacksTests, test_restriction_population) {
  // Require that all potential restrictions are populated before being checked.
  auto tree = getExamplePacksConfig();
  auto packs = tree.get_child("packs");
  Pack fpack("fake_pack", packs.get_child("restricted_pack"));

  ASSERT_FALSE(fpack.getPlatform().empty());
  ASSERT_FALSE(fpack.getVersion().empty());
  ASSERT_EQ(fpack.getShard(), 1U);
}
示例#8
0
int main(int argc, char **argv)
{
  FILE *infile, *outfile;
  unsigned char *buf;
  size_t filelen;

  if(argc < 3)
  {
    fputs("syntax: packbits infile.nam outfile.pkb\n", stderr);
    return 1;
  }

  infile = fopen(argv[1], "rb");
  if(infile == 0)
  {
    fprintf(stderr, "packbits could not open %s for reading\n", argv[1]);
    return 1;
  }
  outfile = fopen(argv[2], "wb");
  if(outfile == 0)
  {
    fprintf(stderr, "packbits could not open %s for writing\n", argv[2]);
    fclose(infile);
    return 1;
  }

//fprintf(stderr, "compressing %s into %s\n", argv[1], argv[2]);

  // get the size of the file
  fseek(infile, 0, SEEK_END);
  filelen = ftell(infile);
  fseek(infile, 0, SEEK_SET);
  printf("reading %lu bytes\n", (unsigned long)filelen);

  buf = malloc(filelen);
  if(buf == 0)
  {
    fprintf(stderr, "packbits could not allocate %lu bytes to hold the file",
            (unsigned long)filelen);
    fclose(infile);
    fclose(outfile);
    return 1;
  }

  fread(buf, 1, filelen, infile);
  fclose(infile);
  /* write length */
  fputc((unsigned char)(filelen >>  8), outfile);
  fputc((unsigned char)(filelen      ), outfile);
  /* write file */
  printf("compressed to %lu bytes.\n", (unsigned long)fpack(buf, filelen, outfile));
  free(buf);
  fclose(outfile);
  return 0;
}
示例#9
0
void frecip(_MIPD_ flash x,flash y)
{ /* set y=1/x */
#ifdef MR_OS_THREADS
    miracl *mr_mip=get_mip();
#endif
    if (mr_mip->ERNUM) return;

    MR_IN(41)

    numer(_MIPP_ x,mr_mip->w1);
    denom(_MIPP_ x,mr_mip->w2);
    fpack(_MIPP_ mr_mip->w2,mr_mip->w1,y);

    MR_OUT
}
示例#10
0
void ftrunc(_MIPD_ flash x,big y,flash z)
{ /* sets y=int(x), z=rem(x) - returns *
   * y only for ftrunc(x,y,y)       */
#ifdef MR_OS_THREADS
    miracl *mr_mip=get_mip();
#endif
    if (mr_mip->ERNUM) return;

    MR_IN(45)
    numer(_MIPP_ x,mr_mip->w1);
    denom(_MIPP_ x,mr_mip->w2);
    divide(_MIPP_ mr_mip->w1,mr_mip->w2,mr_mip->w3);
    copy(mr_mip->w3,y);
    if (y!=z) fpack(_MIPP_ mr_mip->w1,mr_mip->w2,z);
    MR_OUT
}
示例#11
0
void fconv(_MIPD_ int n,int d,flash x)
{ /* convert simple fraction n/d to Flash form */
#ifdef MR_OS_THREADS
    miracl *mr_mip=get_mip();
#endif
    if (mr_mip->ERNUM) return;

    MR_IN(40)
    if (d<0)
    {
        d=(-d);
        n=(-n);
    }
    convert(_MIPP_ n,mr_mip->w5);
    convert(_MIPP_ d,mr_mip->w6);
    fpack(_MIPP_ mr_mip->w5,mr_mip->w6,x);
    MR_OUT
}
示例#12
0
void fpmul(_MIPD_ flash x,int n,int d,flash y)
{ /* multiply x by small fraction n/d - y=x*n/d */
    int r,g;
#ifdef MR_OS_THREADS
    miracl *mr_mip=get_mip();
#endif
    if (mr_mip->ERNUM) return;
    if (n==0 || size(x)==0)
    {
        zero(y);
        return;
    }
    if (n==d)
    {
        copy(x,y);
        return;
    }

    MR_IN(42)

    if (d<0)
    {
        d=(-d);
        n=(-n);
    }
    numer(_MIPP_ x,mr_mip->w1);
    denom(_MIPP_ x,mr_mip->w2);
    r=subdiv(_MIPP_ mr_mip->w1,d,mr_mip->w3);
    g=igcd(d,r);
    r=subdiv(_MIPP_ mr_mip->w2,n,mr_mip->w3);
    g*=igcd(n,r);
    mr_mip->check=OFF;
    premult(_MIPP_ mr_mip->w1,n,mr_mip->w5);
    premult(_MIPP_ mr_mip->w2,d,mr_mip->w6);
    subdiv(_MIPP_ mr_mip->w5,g,mr_mip->w5);
    subdiv(_MIPP_ mr_mip->w6,g,mr_mip->w6);
    mr_mip->check=ON;
    if (fit(mr_mip->w5,mr_mip->w6,mr_mip->nib))
        fpack(_MIPP_ mr_mip->w5,mr_mip->w6,y);
    else
        mround(_MIPP_ mr_mip->w5,mr_mip->w6,y);
    MR_OUT
}
示例#13
0
TEST_F(PacksTests, test_check_platform) {
  Pack fpack("discovery_pack", getPackWithDiscovery());
  EXPECT_TRUE(fpack.checkPlatform());

  // Depending on the current build platform, this check will be true or false.
  fpack.platform_ = kSDKPlatform;
  EXPECT_TRUE(fpack.checkPlatform());

  fpack.platform_ = (kSDKPlatform == "darwin") ? "linux" : "darwin";
  EXPECT_FALSE(fpack.checkPlatform());

  fpack.platform_ = "null";
  EXPECT_TRUE(fpack.checkPlatform());

  fpack.platform_ = "";
  EXPECT_TRUE(fpack.checkPlatform());

  fpack.platform_ = "bad_value";
  EXPECT_FALSE(fpack.checkPlatform());
}
示例#14
0
int main(void) {
  FILE *file = tmpfile();
  size_t len;

  title("fpack()");

  test("s");
  rewind(file);
  len = fpack(file, "s", 0);
  size_ok(len, 1*sizeof(short));
  rewind(file);
  int_ok(fget_short(file), 0);

  test("ss");
  rewind(file);
  len = fpack(file, "ss", 1, 2);
  size_ok(len, 2*sizeof(short));
  rewind(file);
  int_ok(fget_short(file), 1);
  int_ok(fget_short(file), 2);

  test("i");
  rewind(file);
  len = fpack(file, "i", 0);
  size_ok(len, 1*sizeof(int));
  rewind(file);
  int_ok(fget_int(file), 0);

  test("ii");
  rewind(file);
  len = fpack(file, "ii", 1, 2);
  size_ok(len, 2*sizeof(int));
  rewind(file);
  int_ok(fget_int(file), 1);
  int_ok(fget_int(file), 2);

  test("l");
  rewind(file);
  len = fpack(file, "l", 0L);
  long_ok(len, 1*sizeof(long));
  rewind(file);
  long_ok(fget_long(file), 0);

  test("ll");
  rewind(file);
  len = fpack(file, "ll", 1L, 2L);
  long_ok(len, 2*sizeof(long));
  rewind(file);
  long_ok(fget_long(file), 1);
  long_ok(fget_long(file), 2);

  title("funpack()");

  short s1, s2;

  test("s");
  rewind(file);
  fput_short(0, file);
  rewind(file);
  len = funpack(file, "s", &s1);
  size_ok(len, 1*sizeof(short));
  int_ok(s1, 0);

  test("ss");
  rewind(file);
  fput_short(1, file);
  fput_short(2, file);
  rewind(file);
  len = funpack(file, "ss", &s1, &s2);
  size_ok(len, 2*sizeof(short));
  int_ok(s1, 1);
  int_ok(s2, 2);

  int i1, i2;

  test("i");
  rewind(file);
  fput_int(0, file);
  rewind(file);
  len = funpack(file, "i", &i1);
  size_ok(len, 1*sizeof(int));
  int_ok(i1, 0);

  test("ii");
  rewind(file);
  fput_int(1, file);
  fput_int(2, file);
  rewind(file);
  len = funpack(file, "ii", &i1, &i2);
  size_ok(len, 2*sizeof(int));
  int_ok(i1, 1);
  int_ok(i2, 2);

  long l1, l2;

  test("l");
  rewind(file);
  fput_long(0, file);
  rewind(file);
  len = funpack(file, "l", &l1);
  size_ok(len, 1*sizeof(long));
  long_ok(l1, 0);

  test("ll");
  rewind(file);
  fput_long(1, file);
  fput_long(2, file);
  rewind(file);
  len = funpack(file, "ll", &l1, &l2);
  size_ok(len, 2*sizeof(long));
  long_ok(l1, 1);
  long_ok(l2, 2);

  return 0;
}
示例#15
0
void build(_MIPD_ flash x,int (*gen)(_MIPT_ big,int))
{ /* Build x from its regular c.f. *
   * generated by gen()            */
    mr_small ex1,ex2,ex,st,sr;
    int a,b,c,d,rm,q,n,prc,lw2,lw4,lz;
    BOOL finoff,last;
    big t;
#ifdef MR_OS_THREADS
    miracl *mr_mip=get_mip();
#endif
    if (mr_mip->ERNUM) return;

    MR_IN(48)

    zero(mr_mip->w1);
    convert(_MIPP_ 1,mr_mip->w2);
    convert(_MIPP_ 1,mr_mip->w3);
    zero(mr_mip->w4);
    finoff=FALSE;
    last=FALSE;
    n=0;
    q=(*gen)(_MIPP_ x,n);   /* Note - first quotient may be zero */
    ex=mr_mip->base-1;
    if (mr_mip->nib==mr_mip->workprec) prc=mr_mip->nib;
    else prc=mr_mip->workprec+1;
    while (!mr_mip->ERNUM && q>=0)
    {
        if (q==MR_TOOBIG || n==0 || finoff)
        {
            if (q!=MR_TOOBIG) convert(_MIPP_ q,x);
            else last=FALSE;
            mr_mip->check=OFF;
            multiply(_MIPP_ mr_mip->w2,x,mr_mip->w0);
            subtract(_MIPP_ mr_mip->w1,mr_mip->w0,mr_mip->w7);
            mr_mip->check=ON;
            if ((int)(mr_mip->w7->len&MR_OBITS)>mr_mip->nib) break;
            copy(mr_mip->w7,mr_mip->w1);
            t=mr_mip->w1,mr_mip->w1=mr_mip->w2,mr_mip->w2=t;   /* swap(w1,w2) */
            mr_mip->check=OFF;
            multiply(_MIPP_ mr_mip->w4,x,mr_mip->w0);
            subtract(_MIPP_ mr_mip->w3,mr_mip->w0,mr_mip->w7);
            mr_mip->check=ON;
            if ((int)(mr_mip->w7->len&MR_OBITS)>mr_mip->nib)
            { /* oops! */
                fpack(_MIPP_ mr_mip->w1,mr_mip->w4,x);
                negify(x,x);
                mr_mip->EXACT=FALSE;
                MR_OUT
                return;
            }
            copy(mr_mip->w7,mr_mip->w3);
            t=mr_mip->w3,mr_mip->w3=mr_mip->w4,mr_mip->w4=t;   /* swap(w3,w4) */
            n++;
        }
        lw2=(int)(mr_mip->w2->len&MR_OBITS);
        lw4=(int)(mr_mip->w4->len&MR_OBITS);
        lz=lw2+lw4;
        if (lz > prc) break;  /* too big - exit */
        if (last)
        {
            if (finoff) break;
            finoff=TRUE;
            q=(*gen)(_MIPP_ x,n);
            continue;
        }
        if (lz>=prc-1)
        { /* nearly finished - so be careful not to overshoot */
            if (mr_mip->base==0)
            {
#ifndef MR_NOFULLWIDTH
                st=mr_mip->w2->w[lw2-1]+1;
                if (st==0) ex1=1;
                else ex1=muldvm((mr_small)1,(mr_small)0,st,&sr);
                st=mr_mip->w4->w[lw4-1]+1;
                if (st==0) ex2=1;
                else ex2=muldvm((mr_small)1,(mr_small)0,st,&sr);
#endif
            }
            else
            {
                ex1=mr_mip->base/(mr_mip->w2->w[lw2-1]+1);
                ex2=mr_mip->base/(mr_mip->w4->w[lw4-1]+1);
            }
            if (ex2>ex1) ex=ex1,ex1=ex2,ex2=ex;
            if (lz==prc) ex=ex2;
            else         ex=ex1;
            last=TRUE;
        }
        a=1;
        b=0;
        c=0;
        d=1;
        forever
        {
            q=(*gen)(_MIPP_ x,n);          
            if (q<0 || q>=MR_TOOBIG/mr_abs(d))
            { /* there could be more.... *** V3.21 mod *** */
                last=FALSE;
                break;
            }
            rm=b-q*d;
            b=d;
            d=rm;
            rm=a-q*c;
            a=c;
            c=rm;
            n++;
            if ((mr_small)(mr_abs(c-d))>ex) break;
        }
        premult(_MIPP_ mr_mip->w1,c,mr_mip->w7);
        premult(_MIPP_ mr_mip->w1,a,mr_mip->w1);
        premult(_MIPP_ mr_mip->w2,b,mr_mip->w0);
        premult(_MIPP_ mr_mip->w2,d,mr_mip->w2);
        add(_MIPP_ mr_mip->w1,mr_mip->w0,mr_mip->w1);
        add(_MIPP_ mr_mip->w2,mr_mip->w7,mr_mip->w2);
        premult(_MIPP_ mr_mip->w3,c,mr_mip->w7);
        premult(_MIPP_ mr_mip->w3,a,mr_mip->w3);
        premult(_MIPP_ mr_mip->w4,b,mr_mip->w0);
        premult(_MIPP_ mr_mip->w4,d,mr_mip->w4);
        add(_MIPP_ mr_mip->w3,mr_mip->w0,mr_mip->w3);
        add(_MIPP_ mr_mip->w4,mr_mip->w7,mr_mip->w4);
    }
示例#16
0
TEST_F(PacksTests, test_name) {
  Pack fpack("discovery_pack", getPackWithDiscovery());
  fpack.setName("also_discovery_pack");
  EXPECT_EQ(fpack.getName(), "also_discovery_pack");
}
示例#17
0
TEST_F(PacksTests, test_version) {
  Pack fpack("discovery_pack", getPackWithDiscovery());
  EXPECT_EQ(fpack.getVersion(), "1.5.0");
}
示例#18
0
TEST_F(PacksTests, test_platform) {
  Pack fpack("discovery_pack", getPackWithDiscovery());
  EXPECT_EQ(fpack.getPlatform(), "all");
}
示例#19
0
TEST_F(PacksTests, test_schedule) {
  Pack fpack("discovery_pack", getPackWithDiscovery());
  // Expect a single query in the schedule since one query has an explicit
  // invalid/fake platform requirement.
  EXPECT_EQ(fpack.getSchedule().size(), 1U);
}