Esempio n. 1
0
static void
ar5210_decode_txstatus(struct if_ath_alq_payload *a)
{
	struct ar5210_desc txs;

	/* XXX assumes txs is smaller than PAYLOAD_LEN! */
	memcpy(&txs, &a->payload, sizeof(struct ar5210_desc));

	printf("[%u.%06u] [%llu] TXSTATUS\n",
	    (unsigned int) be32toh(a->hdr.tstamp_sec),
	    (unsigned int) be32toh(a->hdr.tstamp_usec),
	    (unsigned long long) be64toh(a->hdr.threadid));

	/* ds_txstatus0 */
	printf("    Frmok=%d, xretries=%d, fifounderrun=%d, filt=%d\n",
	    MF(txs.ds_status0, AR_FrmXmitOK),
	    MF(txs.ds_status0, AR_ExcessiveRetries),
	    MF(txs.ds_status0, AR_FIFOUnderrun),
	    MF(txs.ds_status0, AR_Filtered));
	printf("    LongRetryCnt=%d, ShortRetryCnt=%d\n",
	    MS(txs.ds_status0, AR_LongRetryCnt),
	    MS(txs.ds_status0, AR_ShortRetryCnt));
	printf("    SndTimestamp=0x%04x\n",
	    MS(txs.ds_status0, AR_SendTimestamp));

	/* ds_txstatus1 */
	printf("    Done=%d, SeqNum=0x%04x, AckRSSI=%d\n",
	    MF(txs.ds_status1, AR_Done),
	    txs.ds_status1 & AR_SeqNum,
	    MS(txs.ds_status1, AR_AckSigStrength));

	printf("\n ------\n");
}
Esempio n. 2
0
int OCCFace::createPolygonal(std::vector<OCCStruct3d> points)
{
    try {
        BRepBuilderAPI_MakePolygon MP;
        for (unsigned i=0; i<points.size(); i++) {
            MP.Add(gp_Pnt(points[i].x, points[i].y, points[i].z));
        }
        MP.Close();
        if (!MP.IsDone()) {
            StdFail_NotDone::Raise("failed to create face");;
        }
        BRepBuilderAPI_MakeFace MF(MP.Wire(), false);
        this->setShape(MF.Face());
        
        // possible fix shape
        if (!this->fixShape())
            StdFail_NotDone::Raise("Shapes not valid");
        
    } catch(Standard_Failure &err) {
        Handle_Standard_Failure e = Standard_Failure::Caught();
        const Standard_CString msg = e->GetMessageString();
        if (msg != NULL && strlen(msg) > 1) {
            setErrorMessage(msg);
        } else {
            setErrorMessage("Failed to create face");
        }
        return 0;
    }
    return 1;
}
Esempio n. 3
0
static void
ar5210_decode_rxstatus(struct if_ath_alq_payload *a)
{
	struct ar5210_desc rxs;

	/* XXX assumes rxs is smaller than PAYLOAD_LEN! */
	memcpy(&rxs, &a->payload, sizeof(struct ar5210_desc));

	printf("[%u.%06u] [%llu] RXSTATUS\n",
	    (unsigned int) be32toh(a->hdr.tstamp_sec),
	    (unsigned int) be32toh(a->hdr.tstamp_usec),
	    (unsigned long long) be64toh(a->hdr.threadid));

	printf("  link=0x%08x, data=0x%08x\n",
	    rxs.ds_link,
	    rxs.ds_data);

	/* ds_rxstatus0 */
	printf("  DataLen=%d, ArMore=%d, RSSI=%d, RcvAntenna=0x%x\n",
	    rxs.ds_status0 & AR_DataLen,
	    MF(rxs.ds_status0, AR_More),
	    MS(rxs.ds_status0, AR_RcvSigStrength),
	    MF(rxs.ds_status0, AR_RcvAntenna));

	/* ds_rxstatus1 */
	printf("  RxDone=%d, RxFrameOk=%d, CrcErr=%d, DecryptCrcErr=%d\n",
	    MF(rxs.ds_status1, AR_Done),
	    MF(rxs.ds_status1, AR_FrmRcvOK),
	    MF(rxs.ds_status1, AR_CRCErr),
	    MF(rxs.ds_status1, AR_DecryptCRCErr));
	printf("  KeyIdxValid=%d\n",
	    MF(rxs.ds_status1, AR_KeyIdxValid));

	printf("  PhyErrCode=0x%02x\n",
	    MS(rxs.ds_status1, AR_PHYErr));

	printf("  KeyMiss=%d\n",
	    MF(rxs.ds_status1, AR_KeyCacheMiss));

	printf("  Timetamp: 0x%05x\n",
	    MS(rxs.ds_status1, AR_RcvTimestamp));

	printf("\n ------\n");
}
Esempio n. 4
0
void occQt::makeFillet()
{
    gp_Ax2 anAxis;
    anAxis.SetLocation(gp_Pnt(0.0, 50.0, 0.0));

    TopoDS_Shape aTopoBox = BRepPrimAPI_MakeBox(anAxis, 3.0, 4.0, 5.0);
    BRepFilletAPI_MakeFillet MF(aTopoBox);

    // Add all the edges to fillet.
    for (TopExp_Explorer ex(aTopoBox, TopAbs_EDGE); ex.More(); ex.Next())
    {
        MF.Add(1.0, TopoDS::Edge(ex.Current()));
    }

    Handle_AIS_Shape anAisShape = new AIS_Shape(MF.Shape());
    anAisShape->SetColor(Quantity_NOC_VIOLET);

    mContext->Display(anAisShape);
}
Esempio n. 5
0
static void
ar5212_decode_txstatus(struct if_ath_alq_payload *a)
{
	struct ar5212_desc txs;

	/* XXX assumes txs is smaller than PAYLOAD_LEN! */
	memcpy(&txs, &a->payload, sizeof(struct ar5212_desc));

	printf("[%u.%06u] [%llu] TXSTATUS: TxDone=%d, TS=0x%08x\n\n",
	    (unsigned int) be32toh(a->hdr.tstamp_sec),
	    (unsigned int) be32toh(a->hdr.tstamp_usec),
	    (unsigned long long) be64toh(a->hdr.threadid),
	    MF(txs.u.tx.status1, AR_Done),
	    MS(txs.u.tx.status0, AR_SendTimestamp));

	/* ds_txstatus0 */
	printf("    Frmok=%d, xretries=%d, fifounderrun=%d, filt=%d\n",
	    MF(txs.u.tx.status0, AR_FrmXmitOK),
	    MF(txs.u.tx.status0, AR_ExcessiveRetries),
	    MF(txs.u.tx.status0, AR_FIFOUnderrun),
	    MF(txs.u.tx.status0, AR_Filtered));
	printf("    RTScnt=%d, FailCnt=%d, VCollCnt=%d\n",
	    MS(txs.u.tx.status0, AR_RTSFailCnt),
	    MS(txs.u.tx.status0, AR_DataFailCnt),
	    MS(txs.u.tx.status0, AR_VirtCollCnt));
	printf("    SndTimestamp=0x%04x\n",
	    MS(txs.u.tx.status0, AR_SendTimestamp));

	/* ds_txstatus1 */
	printf("    Done=%d, SeqNum=0x%04x, AckRSSI=%d, FinalTSI=%d\n",
	    MF(txs.u.tx.status1, AR_Done),
	    MS(txs.u.tx.status1, AR_SeqNum),
	    MS(txs.u.tx.status1, AR_AckSigStrength),
	    MS(txs.u.tx.status1, AR_FinalTSIndex));
	printf("    CompSuccess=%d, XmitAntenna=%d\n",
	    MF(txs.u.tx.status1, AR_CompSuccess),
	    MF(txs.u.tx.status1, AR_XmitAtenna));

	printf("\n ------\n");
}
Esempio n. 6
0
int AgentCalcReward (int *area)
{
	static int ball = 0;
	int reward = MAX_E(ball);
	int rot;

	rot = AGENT_MOT(AGENT_SCL,AGENT_DIR,4) ? 1 : -1;

/*
 * Randomly permute reward signal
 */
	MF(d)[MAX_E(ball)][MAY_E(ball)] = EMPTY;

	reward += rot * (rand() % (ScoreDiff+1));
	MAX_E(ball) = reward;

	ball += reward;
	reward  = 0;
	return reward;
}
Esempio n. 7
0
int OCCFace::createFace(std::vector<OCCWire *> wires) {
    try {
        const TopoDS_Wire& outerwire = wires[0]->getWire();
        
        if (!wires[0]->isClosed())
            StdFail_NotDone::Raise("Outer wire not closed");
        
        BRepBuilderAPI_MakeFace MF(outerwire);
        
        // add optional holes
        for (unsigned i = 1; i < wires.size(); i++) {
            const TopoDS_Wire& wire = wires[i]->getWire();
            if (!wires[i]->isClosed())
                StdFail_NotDone::Raise("Outer wire not closed");
        
            if (wire.Orientation() != outerwire.Orientation()) {
                MF.Add(TopoDS::Wire(wire.Reversed()));
            } else {
                MF.Add(wire);
            }
        }
        this->setShape(MF.Shape());
        
        // possible fix shape
        if (!this->fixShape())
            StdFail_NotDone::Raise("Shapes not valid");
        
    } catch(Standard_Failure &err) {
        Handle_Standard_Failure e = Standard_Failure::Caught();
        const Standard_CString msg = e->GetMessageString();
        if (msg != NULL && strlen(msg) > 1) {
            setErrorMessage(msg);
        } else {
            setErrorMessage("Failed to create face");
        }
        return 0;
    }
    return 1;
}
Esempio n. 8
0
int mpac_print_ipheader(sniff_cntx* context){
	printf("\n\n---------IP Header Starts----\n\n");

	printf("Version                       : %d \n", IP_V(context->ipHeader));
	printf("Header length                 : %d \n", context->ipHeaderSize);
	printf("Type of service               : %d \n", context->ipHeader->ip_tos);
	printf("Datagram length               : %d \n", context->ipHeader->ip_len);
	printf("Identication no.              : %d \n", context->ipHeader->ip_id);
	printf("Offset                        : %d \n", IP_OFF(context->ipHeader));
	printf("Reserved fragment bit         : %d \n", RF(context->ipHeader));
	printf("Dont fragment bit             : %d \n", DF(context->ipHeader));
	printf("More fragment bit             : %d \n", MF(context->ipHeader));
	printf("Time to live                  : %d \n", context->ipHeader->ip_ttl);
	printf("Protocol                      : %d \n", context->ipHeader->ip_p);
	printf("Checksum                      : %d \n", context->ipHeader->ip_sum);
	printf("Source IP                     : %s\n",inet_ntoa(context->ipHeader->ip_src));
	printf("Destination IP                : %s\n",inet_ntoa(context->ipHeader->ip_dst));



	printf("\n\n---------IP Header Ends----\n\n");

	return 0;
}
Esempio n. 9
0
static void
ar5210_decode_txdesc(struct if_ath_alq_payload *a)
{
	struct ar5210_desc txc;

	/* XXX assumes txs is smaller than PAYLOAD_LEN! */
	memcpy(&txc, &a->payload, sizeof(struct ar5210_desc));

	printf("[%u.%06u] [%llu] TXD\n",
	    (unsigned int) be32toh(a->hdr.tstamp_sec),
	    (unsigned int) be32toh(a->hdr.tstamp_usec),
	    (unsigned long long) be64toh(a->hdr.threadid));

	printf("  link=0x%08x, data=0x%08x\n",
	    txc.ds_link,
	    txc.ds_data);

	/* ds_ctl0 */
	printf("    Frame Len=%d\n", txc.ds_ctl0 & AR_FrameLen);
	printf("    TX Rate=0x%02x, RtsEna=%d, ClrDstMask=%d AntModeXmit=0x%02x\n",
	    MS(txc.ds_ctl0, AR_XmitRate),
	    MF(txc.ds_ctl0, AR_RTSCTSEnable),
	    MF(txc.ds_ctl0, AR_ClearDestMask),
	    MF(txc.ds_ctl0, AR_AntModeXmit));
	printf("    FrmType=0x%02x, TxIntrReq=%d\n",
	    MS(txc.ds_ctl0, AR_FrmType),
	    MF(txc.ds_ctl0, AR_TxInterReq));
	printf("    LongPkt=%d\n", MF(txc.ds_ctl0, AR_LongPkt));

	/* ds_ctl1 */
	printf("    BufLen=%d, TxMore=%d, EncryptKeyIdx=%d, RtsDuration=%d\n",
	    txc.ds_ctl1 & AR_BufLen,
	    MF(txc.ds_ctl1, AR_More),
	    MS(txc.ds_ctl1, AR_EncryptKeyIdx),
	    MS(txc.ds_ctl1, AR_RTSDuration));

	printf("\n ------ \n");
}
Esempio n. 10
0
int main(int argc, char* argv[]){
    if(argc != 3){
        printf("Useage: input_name output_name");
        exit(0);
    }
    
    char file_answer;
    
    printf("Select mode:\n"
           "1.bin to bmp\n"
           "2.bmp to bmp\n"
           "3.bin to bin\n");
    file_answer=getchar();
    fflush(stdin);
    
    char *Input=argv[1], *Output=argv[2];//retrive input/output name from commandline
    BmpHead *pBmpHeader = new BmpHead;
    unsigned char **pucImageData; 
    char *pcColorMap=NULL;
           
    if((file_answer == '1')||(file_answer == '3')){   //read bin file
        system("cls");
        
        //assign header information courtersy of Lena.bin
	    (*pBmpHeader).bfType=19778;
	    (*pBmpHeader).bfSize=54 + 1024+ 512*512 ; // raw data size = 512*512 = 262144 bytes, modify when necessary
	    (*pBmpHeader).bfReserved=0;
	    (*pBmpHeader).bfOffBits=1078;
	    (*pBmpHeader).biSize=40;
	    (*pBmpHeader).biWidth= 512;		//number of columns of the image
	    (*pBmpHeader).biHeight= 512;		//number of rows of the image
	    (*pBmpHeader).biPlanes=1;
	    (*pBmpHeader).biBitCount=8;
	    (*pBmpHeader).biCompression=0;
	    (*pBmpHeader).biSizeImage= 512*512;	//raw data size = 512*512 = 26144 bytes, modify when necessary, e.g., a 256x256 image: raw data size = 256*256
	    (*pBmpHeader).biXPelsPerMeter=2834;
	    (*pBmpHeader).biYpelsPerMeter=2834;
	    (*pBmpHeader).biClrUsed=0;
	    (*pBmpHeader).biClrImportant=0;
        
        //read provided colormap
        FILE *colormap=NULL;
        pcColorMap = new char [1024];
        if((colormap=fopen("colormap.bin", "rb")) == NULL){
            printf("Failed to find colormap.bin\n");
            exit(0);
        }
        fread(pcColorMap, sizeof(char), pBmpHeader->bfOffBits-64, colormap);
        fclose(colormap);
        
        //read raw data fron input
        pucImageData = ReadImage( Input, pBmpHeader->biWidth, 0);
        
        printf("successfully read raw data from %s.\n\n", Input);
    }
     
    else if(file_answer == '2'){  //read bmp file
        system("cls");
        
        //read input header infomation
        pBmpHeader=ReadBmpHeader(Input);
        printf("raw data size: %d\n", pBmpHeader->biSizeImage);
        printf("Image Width: %d\n", pBmpHeader->biWidth);
        printf("Image Height %d\n", pBmpHeader->biHeight);
	    printf("Header occupies 54 bytes\n");
        printf("Color map occupies 1024 bytes\n");	
        
        //read input colormap
        pcColorMap=ReadColorMap(Input, 1024);
        
        //read raw data from input
                                                    //set offset=1024+54
        pucImageData=ReadImage(Input, pBmpHeader->biWidth, 1078);
        printf("successfully read raw data from %s.\n\n", Input);
    }
    
    srand(time(NULL));//plant random seed
    
    //function menu
    char fx_answer;
    int width, cutoff;
    do{
        printf(
           "Select function:\n"
           "A.Turn Lena upside down\n"
           "B.Turn Lena around\n"
           "C.Rotate Lena by 45 deg clockwise\n"
           "D.Shrink Lena by half\n"
           "E.Invert Lena\n"
           "F.Add normal noise to Lena\n"
           "G.Add impluse noise to Lena\n"
           "H.Moving average filtering\n"
           "I.Midian filtering\n"
           "J.Differential flitering\n"
           "K.LPF\n"
           "L.HPF\n"
           "\n0.Exit\n");
        printf("Your choice: [_]\b\b");
        fx_answer = getchar();
        fx_answer = tolower(fx_answer);
        fflush(stdin);
        
        switch(fx_answer){//savefile(): ask user to save as picture or not
            case 'a':// selected: turn lena upside down
                UpsideDown(pucImageData, pBmpHeader->biWidth);
                savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap);
                break;
            
            case 'b'://selected: turn lena around
                LeftRight(pucImageData, pBmpHeader->biWidth);
                savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap);
                break;
                 
            case 'c'://selected: rotate lena
                ImgRotate(pucImageData, pBmpHeader->biWidth, 45);
                savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap);
                break;
            
            case 'd'://selected: shrink lena
                Shrink(pucImageData, pBmpHeader->biWidth, pBmpHeader, 2);
                savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap);
                break;
                 
            case 'e'://selected: invert lena
                Invert(pucImageData, pBmpHeader->biWidth);
                savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap);
                break;
                 
            case 'f'://selected: add noise
                NormalNoise(pucImageData, pBmpHeader->biWidth);
                savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap);
                break;
                 
            case 'g'://selected: add paper n salt noise
                ImpluseNoise(pucImageData, pBmpHeader->biWidth);
                savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap);
                break;
                 
            case 'h'://selected: moving average filter
                //ask user to input sampling width
                printf("Enter sampling width:");
                scanf("%d", &width);
                fflush(stdin);
                MAF(pucImageData, pBmpHeader->biWidth, width);
                savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap);
                break;
                 
            case 'i'://selected: moving midian filter
                //ask user to input sampling width
                printf("Enter sampling width:");
                scanf("%d", &width);
                fflush(stdin);
                MF(pucImageData, pBmpHeader->biWidth, width);
                savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap);
                break;
                 
            case 'j'://selected: differential filter
                DIF(pucImageData, pBmpHeader->biWidth);
                savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap);
                break;
                 
            case 'k'://selected: low-pass filter
                //ask user to input cutoff frequency
                printf("Enter cutoff frenquency(0~%d):", (int)pBmpHeader->biWidth/2);
                scanf("%d", &cutoff);
                fflush(stdin);
                LPF(pucImageData, pBmpHeader->biWidth, cutoff);
                savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap);
                break;
                 
            case 'l'://selected: high-pass filter
                //ask user to input cutoff frequency
                printf("Enter cutoff frenquency(0~%d):", (int)pBmpHeader->biWidth/2);
                scanf("%d", &cutoff);
                fflush(stdin);
                HPF(pucImageData, pBmpHeader->biWidth, cutoff);
                savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap);
                break;
                 
            case '0'://selected: exit
                //ask one last time whether user want to save or not
                savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap);
                break;
                 
            default:
                system("cls");
                printf("Your choice is not in the list!\n");
                break;
            
        }
        
        if(fx_answer == 0)
            break;//selected: exit. break the loop
        
        
    } while(fx_answer != '0');
    
    //returning dynamic allocated memory
    delete [] pcColorMap;
    delete [] pucImageData;
    delete pBmpHeader;
    pcColorMap=NULL;
    pucImageData=NULL;
    pBmpHeader=NULL;
    
    printf("EOP\n");
}
Esempio n. 11
0
static void
ar5416_decode_txstatus(struct if_ath_alq_payload *a)
{
	struct ar5416_desc txs;

	/* XXX assumes txs is smaller than PAYLOAD_LEN! */
	memcpy(&txs, &a->payload, sizeof(struct ar5416_desc));

	printf("[%u.%06u] [%llu] TXSTATUS: TxDone=%d, FrmOk=%d, filt=%d, TS=0x%08x\n",
	    (unsigned int) be32toh(a->hdr.tstamp_sec),
	    (unsigned int) be32toh(a->hdr.tstamp_usec),
	    (unsigned long long) be64toh(a->hdr.threadid),
	    MF(txs.u.tx.status[9], AR_TxDone),
	    MF(txs.u.tx.status[1], AR_FrmXmitOK),
	    MF(txs.u.tx.status[1], AR_Filtered),
	    txs.u.tx.status[2]);

	/* ds_txstatus0 */
	printf("    RX RSSI 0 [%d %d %d]",
	    MS(txs.u.tx.status[0], AR_TxRSSIAnt00),
	    MS(txs.u.tx.status[0], AR_TxRSSIAnt01),
	    MS(txs.u.tx.status[0], AR_TxRSSIAnt02));

	/* ds_txstatus5 */
	printf(" RX RSSI 1 [%d %d %d] Comb=%d\n",
	    MS(txs.u.tx.status[5], AR_TxRSSIAnt10),
	    MS(txs.u.tx.status[5], AR_TxRSSIAnt11),
	    MS(txs.u.tx.status[5], AR_TxRSSIAnt12),
	    MS(txs.u.tx.status[5], AR_TxRSSICombined));

	/* ds_txstatus0 */
	printf("    BA Valid=%d",
	    MF(txs.u.tx.status[0], AR_TxBaStatus));

	/* ds_txstatus1 */
	printf(", Frmok=%d, xretries=%d, fifounderrun=%d, filt=%d\n",
	    MF(txs.u.tx.status[1], AR_FrmXmitOK),
	    MF(txs.u.tx.status[1], AR_ExcessiveRetries),
	    MF(txs.u.tx.status[1], AR_FIFOUnderrun),
	    MF(txs.u.tx.status[1], AR_Filtered));
	printf("    DelimUnderrun=%d, DataUnderun=%d, DescCfgErr=%d,"
	    " TxTimerExceeded=%d\n",
	    MF(txs.u.tx.status[1], AR_TxDelimUnderrun),
	    MF(txs.u.tx.status[1], AR_TxDataUnderrun),
	    MF(txs.u.tx.status[1], AR_DescCfgErr),
	    MF(txs.u.tx.status[1], AR_TxTimerExpired));

	printf("    RTScnt=%d, FailCnt=%d, VRetryCnt=%d\n",
	    MS(txs.u.tx.status[1], AR_RTSFailCnt),
	    MS(txs.u.tx.status[1], AR_DataFailCnt),
	    MS(txs.u.tx.status[1], AR_VirtRetryCnt));

	/* ds_txstatus2 */
	printf("    TxTimestamp=0x%08x", txs.u.tx.status[2]);

	/* ds_txstatus3 */
	/* ds_txstatus4 */
	printf(", BALow=0x%08x", txs.u.tx.status[3]);
	printf(", BAHigh=0x%08x\n", txs.u.tx.status[4]);


	/* ds_txstatus6 */
	/* ds_txstatus7 */
	/* ds_txstatus8 */
	printf("    TxEVM[0]=0x%08x, TxEVM[1]=0x%08x, TxEVM[2]=0x%08x\n",
	    txs.u.tx.status[6],
	    txs.u.tx.status[7],
	    txs.u.tx.status[8]);

	/* ds_txstatus9 */
	printf("    TxDone=%d, SeqNum=0x%04x, TxOpExceeded=%d, FinalTsIdx=%d\n",
	    MF(txs.u.tx.status[9], AR_TxDone),
	    MS(txs.u.tx.status[9], AR_SeqNum),
	    MF(txs.u.tx.status[9], AR_TxOpExceeded),
	    MS(txs.u.tx.status[9], AR_FinalTxIdx));
	printf("    PowerMgmt=%d, TxTid=%d\n",
	    MF(txs.u.tx.status[9], AR_PowerMgmt),
	    MS(txs.u.tx.status[9], AR_TxTid));

	printf("\n ------\n");
}
Esempio n. 12
0
static void
ar5416_decode_rxstatus(struct if_ath_alq_payload *a)
{
	struct ar5416_desc rxs;

	/* XXX assumes rxs is smaller than PAYLOAD_LEN! */
	memcpy(&rxs, &a->payload, sizeof(struct ar5416_desc));

	printf("[%u.%06u] [%llu] RXSTATUS: RxDone=%d, RxRate=0x%02x, TS=0x%08x\n",
	    (unsigned int) be32toh(a->hdr.tstamp_sec),
	    (unsigned int) be32toh(a->hdr.tstamp_usec),
	    (unsigned long long) be64toh(a->hdr.threadid),
	    MF(rxs.ds_rxstatus8, AR_RxDone),
	    MS(rxs.ds_rxstatus0, AR_RxRate),
	    rxs.ds_rxstatus2);

	printf("  link=0x%08x, data=0x%08x, ctl0=0x%08x, ctl2=0x%08x\n",
	    rxs.ds_link,
	    rxs.ds_data,
	    rxs.ds_ctl0,
	    rxs.ds_ctl1);

	/* status0 */
	/*
	 * XXX TODO: For AR9285, the chain 1 and chain 2 RSSI values
	 * acutally contain the RX mixer configuration
	 */
	printf("  RSSICtl[0]=%d, RSSICtl[1]=%d, RSSICtl[2]=%d\n",
	    MS(rxs.ds_rxstatus0, AR_RxRSSIAnt00),
	    MS(rxs.ds_rxstatus0, AR_RxRSSIAnt01),
	    MS(rxs.ds_rxstatus0, AR_RxRSSIAnt02));

	/* status4 */
	printf("  RSSIExt[0]=%d, RSSIExt[1]=%d, RSSIExt[2]=%d, RSSIComb=%d\n",
	    MS(rxs.ds_rxstatus4, AR_RxRSSIAnt10),
	    MS(rxs.ds_rxstatus4, AR_RxRSSIAnt11),
	    MS(rxs.ds_rxstatus4, AR_RxRSSIAnt12),
	    MS(rxs.ds_rxstatus4, AR_RxRSSICombined));

	/* status2 */
	printf("  RxTimestamp=0x%08x,", rxs.ds_rxstatus2);

	/* status1 */
	printf(" DataLen=%d, RxMore=%d, NumDelim=%d\n",
	    rxs.ds_rxstatus1 & AR_DataLen,
	    MF(rxs.ds_rxstatus1, AR_RxMore),
	    MS(rxs.ds_rxstatus1, AR_NumDelim));

	/* status3 - RxRate however is for Owl 2.0 */
	printf("  GI=%d, 2040=%d, RxRate=0x%02x, DupFrame=%d, RxAnt=0x%08x\n",
	    MF(rxs.ds_rxstatus3, AR_GI),
	    MF(rxs.ds_rxstatus3, AR_2040),
	    MS(rxs.ds_rxstatus0, AR_RxRate),
	    MF(rxs.ds_rxstatus3, AR_DupFrame),
	    MS(rxs.ds_rxstatus3, AR_RxAntenna));

	/* status5 */
	/* status6 */
	/* status7 */
	printf("  RxEvm0=0x%08x, RxEvm1=0x%08x, RxEvm2=0x%08x\n",
	    rxs.ds_rxstatus5,
	    rxs.ds_rxstatus6,
	    rxs.ds_rxstatus7);
	
	/* status8 */
	printf("  RxDone=%d, RxFrameOk=%d, CrcErr=%d, DecryptCrcErr=%d\n",
	    MF(rxs.ds_rxstatus8, AR_RxDone),
	    MF(rxs.ds_rxstatus8, AR_RxFrameOK),
	    MF(rxs.ds_rxstatus8, AR_CRCErr),
	    MF(rxs.ds_rxstatus8, AR_DecryptCRCErr));
	printf("  PhyErr=%d, MichaelErr=%d, PreDelimCRCErr=%d, KeyIdxValid=%d\n",
	    MF(rxs.ds_rxstatus8, AR_PHYErr),
	    MF(rxs.ds_rxstatus8, AR_MichaelErr),
	    MF(rxs.ds_rxstatus8, AR_PreDelimCRCErr),
	    MF(rxs.ds_rxstatus8, AR_RxKeyIdxValid));

	printf("  RxMoreAggr=%d, RxAggr=%d, PostDelimCRCErr=%d, HiRxChain=%d\n",
	    MF(rxs.ds_rxstatus8, AR_RxMoreAggr),
	    MF(rxs.ds_rxstatus8, AR_RxAggr),
	    MF(rxs.ds_rxstatus8, AR_PostDelimCRCErr),
	    MF(rxs.ds_rxstatus8, AR_HiRxChain));

	/* If PHY error, print that out. Otherwise, the key index */
	if (MF(rxs.ds_rxstatus8, AR_PHYErr))
		printf("  PhyErrCode=0x%02x",
		    MS(rxs.ds_rxstatus8, AR_PHYErrCode));
	else
		printf("  KeyIdx=0x%02x",
		    MS(rxs.ds_rxstatus8, AR_KeyIdx));
	printf(", KeyMiss=%d\n",
	    MF(rxs.ds_rxstatus8, AR_KeyMiss));

	printf("\n ------\n");
}
Esempio n. 13
0
static void
ar5416_decode_txdesc(struct if_ath_alq_payload *a)
{
	struct ar5416_desc txc;

	/* XXX assumes txs is smaller than PAYLOAD_LEN! */
	memcpy(&txc, &a->payload, sizeof(struct ar5416_desc));

	printf("[%u.%06u] [%llu] TXD\n",
	    (unsigned int) be32toh(a->hdr.tstamp_sec),
	    (unsigned int) be32toh(a->hdr.tstamp_usec),
	    (unsigned long long) be64toh(a->hdr.threadid));

	printf("  link=0x%08x, data=0x%08x\n",
	    txc.ds_link,
	    txc.ds_data);

	/* ds_ctl0 */
	printf("    Frame Len=%d, VMF=%d\n",
	     txc.ds_ctl0 & AR_FrameLen,
	    MF(txc.ds_ctl0, AR_VirtMoreFrag));
	printf("    TX power0=%d, RtsEna=%d, Veol=%d, ClrDstMask=%d\n",
	    MS(txc.ds_ctl0, AR_XmitPower),
	    MF(txc.ds_ctl0, AR_RTSEnable),
	    MF(txc.ds_ctl0, AR_VEOL),
	    MF(txc.ds_ctl0, AR_ClrDestMask));
	printf("    TxIntrReq=%d, DestIdxValid=%d, CtsEnable=%d\n",
	    MF(txc.ds_ctl0, AR_TxIntrReq),
	    MF(txc.ds_ctl0, AR_DestIdxValid),
	    MF(txc.ds_ctl0, AR_CTSEnable));

	/* ds_ctl1 */
	printf("    BufLen=%d, TxMore=%d, DestIdx=%d,"
	    " FrType=0x%x\n",
	    txc.ds_ctl1 & AR_BufLen,
	    MF(txc.ds_ctl1, AR_TxMore),
	    MS(txc.ds_ctl1, AR_DestIdx),
	    MS(txc.ds_ctl1, AR_FrameType));
	printf("    NoAck=%d, InsertTs=%d, CorruptFcs=%d, ExtOnly=%d,"
	    " ExtAndCtl=%d\n",
	    MF(txc.ds_ctl1, AR_NoAck),
	    MF(txc.ds_ctl1, AR_InsertTS),
	    MF(txc.ds_ctl1, AR_CorruptFCS),
	    MF(txc.ds_ctl1, AR_ExtOnly),
	    MF(txc.ds_ctl1, AR_ExtAndCtl));
	printf("    MoreAggr=%d, IsAggr=%d, MoreRifs=%d\n",
	    MF(txc.ds_ctl1, AR_MoreAggr),
	    MF(txc.ds_ctl1, AR_IsAggr),
	    MF(txc.ds_ctl1, AR_MoreRifs));

	/* ds_ctl2 */
	printf("    DurUpEna=%d, Burstdur=0x%04x\n",
	    MF(txc.ds_ctl2, AR_DurUpdateEn),
	    MS(txc.ds_ctl2, AR_BurstDur));
	printf("    Try0=%d, Try1=%d, Try2=%d, Try3=%d\n",
	    MS(txc.ds_ctl2, AR_XmitDataTries0),
	    MS(txc.ds_ctl2, AR_XmitDataTries1),
	    MS(txc.ds_ctl2, AR_XmitDataTries2),
	    MS(txc.ds_ctl2, AR_XmitDataTries3));

	/* ds_ctl3, 4 */
	printf("    try 0: Rate=0x%02x, PktDur=%d, RTS/CTS ena=%d\n",
	    MS(txc.ds_ctl3, AR_XmitRate0),
	    MS(txc.ds_ctl4, AR_PacketDur0),
	    MF(txc.ds_ctl4, AR_RTSCTSQual0));
	printf("    try 1: Rate=0x%02x, PktDur=%d, RTS/CTS ena=%d\n",
	    MS(txc.ds_ctl3, AR_XmitRate1),
	    MS(txc.ds_ctl4, AR_PacketDur1),
	    MF(txc.ds_ctl4, AR_RTSCTSQual1));

	/* ds_ctl3, 5 */
	printf("    try 2: Rate=0x%02x, PktDur=%d, RTS/CTS ena=%d\n",
	    MS(txc.ds_ctl3, AR_XmitRate2),
	    MS(txc.ds_ctl5, AR_PacketDur2),
	    MF(txc.ds_ctl5, AR_RTSCTSQual2));
	printf("    try 3: Rate=0x%02x, PktDur=%d, RTS/CTS ena=%d\n",
	    MS(txc.ds_ctl3, AR_XmitRate3),
	    MS(txc.ds_ctl5, AR_PacketDur3),
	    MF(txc.ds_ctl5, AR_RTSCTSQual3));

	/* ds_ctl6 */
	printf("    AggrLen=%d, PadDelim=%d, EncrType=%d\n",
	    MS(txc.ds_ctl6, AR_AggrLen),
	    MS(txc.ds_ctl6, AR_PadDelim),
	    MS(txc.ds_ctl6, AR_EncrType));

	/* ds_ctl7 */
	printf("    try 0: chainMask=0x%x, GI=%d, 2040=%d, STBC=%d\n",
	    MS(txc.ds_ctl7, AR_ChainSel0),
	    MF(txc.ds_ctl7, AR_GI0),
	    MF(txc.ds_ctl7, AR_2040_0),
	    MF(txc.ds_ctl7, AR_STBC0));
	printf("    try 1: chainMask=0x%x, GI=%d, 2040=%d, STBC=%d\n",
	    MS(txc.ds_ctl7, AR_ChainSel1),
	    MF(txc.ds_ctl7, AR_GI1),
	    MF(txc.ds_ctl7, AR_2040_1),
	    MF(txc.ds_ctl7, AR_STBC1));
	printf("    try 2: chainMask=0x%x, GI=%d, 2040=%d, STBC=%d\n",
	    MS(txc.ds_ctl7, AR_ChainSel2),
	    MF(txc.ds_ctl7, AR_GI2),
	    MF(txc.ds_ctl7, AR_2040_2),
	    MF(txc.ds_ctl7, AR_STBC2));
	printf("    try 3: chainMask=0x%x, GI=%d, 2040=%d, STBC=%d\n",
	    MS(txc.ds_ctl7, AR_ChainSel3),
	    MF(txc.ds_ctl7, AR_GI3),
	    MF(txc.ds_ctl7, AR_2040_3),
	    MF(txc.ds_ctl7, AR_STBC3));

	printf("    RTSCtsRate=0x%02x\n", MS(txc.ds_ctl7, AR_RTSCTSRate));

	/* ds_ctl8 */
	printf("    try 0: ant=0x%08x\n", txc.ds_ctl8 &  AR_AntCtl0);

	/* ds_ctl9 */
	printf("    try 1: TxPower=%d, ant=0x%08x\n",
	    MS(txc.ds_ctl9, AR_XmitPower1),
	    txc.ds_ctl9 & AR_AntCtl1);

	/* ds_ctl10 */
	printf("    try 2: TxPower=%d, ant=0x%08x\n",
	    MS(txc.ds_ctl10, AR_XmitPower2),
	    txc.ds_ctl10 & AR_AntCtl2);

	/* ds_ctl11 */
	printf("    try 3: TxPower=%d, ant=0x%08x\n",
	    MS(txc.ds_ctl11, AR_XmitPower3),
	    txc.ds_ctl11 & AR_AntCtl3);

	printf("\n ------ \n");
}
Esempio n. 14
0
static void
ar9300_decode_txstatus(struct if_ath_alq_payload *a)
{
	struct ar9300_txs txs;

	/* XXX assumes txs is smaller than PAYLOAD_LEN! */
	memcpy(&txs, &a->payload, sizeof(struct ar9300_txs));

	printf("[%u.%06u] [%llu] TXSTATUS\n",
	    (unsigned int) be32toh(a->hdr.tstamp_sec),
	    (unsigned int) be32toh(a->hdr.tstamp_usec),
	    (unsigned long long) be64toh(a->hdr.threadid));
	printf("    DescId=0x%08x\n", txs.status1);

	printf("    DescLen=%d, TxQcuNum=%d, CtrlStat=%d, DescId=0x%04x\n",
	    txs.ds_info & 0xff,
	    MS(txs.ds_info, AR_tx_qcu_num),
	    MS(txs.ds_info, AR_ctrl_stat),
	    MS(txs.ds_info, AR_desc_id));

	printf("    TxTimestamp=0x%08x\n", txs.status4);

	printf("    TxDone=%d, SeqNo=%d, TxOpExceed=%d, TXBFStatus=%d\n",
	    MF(txs.status8, AR_tx_done),
	    MS(txs.status8, AR_seq_num),
	    MF(txs.status8, AR_tx_op_exceeded),
	    MS(txs.status8, AR_TXBFStatus));

	printf("    TXBfMismatch=%d, BFStreamMiss=%d, FinalTxIdx=%d\n",
	    MF(txs.status8, AR_tx_bf_bw_mismatch),
	    MF(txs.status8, AR_tx_bf_stream_miss),
	    MS(txs.status8, AR_final_tx_idx));

	printf("    TxBfDestMiss=%d, TxBfExpired=%d, PwrMgmt=%d, Tid=%d,"
	    " FastTsBit=%d\n",
	    MF(txs.status8, AR_tx_bf_dest_miss),
	    MF(txs.status8, AR_tx_bf_expired),
	    MF(txs.status8, AR_power_mgmt),
	    MS(txs.status8, AR_tx_tid),
	    MF(txs.status8, AR_tx_fast_ts));

	printf("    Frmok=%d, xretries=%d, fifounderrun=%d, filt=%d\n",
	    MF(txs.status3, AR_frm_xmit_ok),
	    MF(txs.status3, AR_excessive_retries),
	    MF(txs.status3, AR_fifounderrun),
	    MF(txs.status3, AR_filtered));
	printf("    DelimUnderrun=%d, DataUnderun=%d, DescCfgErr=%d,"
	    " TxTimerExceeded=%d\n",
	    MF(txs.status3, AR_tx_delim_underrun),
	    MF(txs.status3, AR_tx_data_underrun),
	    MF(txs.status3, AR_desc_cfg_err),
	    MF(txs.status3, AR_tx_timer_expired));

	printf("    RTScnt=%d, FailCnt=%d, VRetryCnt=%d\n",
	    MS(txs.status3, AR_rts_fail_cnt),
	    MS(txs.status3, AR_data_fail_cnt),
	    MS(txs.status3, AR_virt_retry_cnt));



	printf("    RX RSSI 0 [%d %d %d]\n",
	    MS(txs.status2, AR_tx_rssi_ant00),
	    MS(txs.status2, AR_tx_rssi_ant01),
	    MS(txs.status2, AR_tx_rssi_ant02));

	printf("    RX RSSI 1 [%d %d %d] Comb=%d\n",
	    MS(txs.status7, AR_tx_rssi_ant10),
	    MS(txs.status7, AR_tx_rssi_ant11),
	    MS(txs.status7, AR_tx_rssi_ant12),
	    MS(txs.status7, AR_tx_rssi_combined));

	printf("    BA Valid=%d\n",
	    MF(txs.status2, AR_tx_ba_status));

	printf("    BALow=0x%08x\n", txs.status5);
	printf("    BAHigh=0x%08x\n", txs.status6);

	printf("\n ------ \n");
}
Esempio n. 15
0
/*
 * Note - these are rounded up to 128 bytes; but we
 * only use 96 bytes from it.
 */
static void
ar9300_decode_txdesc(struct if_ath_alq_payload *a)
{
	struct ar9300_txc txc;

	/* XXX assumes txs is smaller than PAYLOAD_LEN! */
	memcpy(&txc, &a->payload, 96);

	printf("[%u.%06u] [%llu] TXD\n",
	    (unsigned int) be32toh(a->hdr.tstamp_sec),
	    (unsigned int) be32toh(a->hdr.tstamp_usec),
	    (unsigned long long) be64toh(a->hdr.threadid));

	printf("  DescLen=%d, TxQcuNum=%d, CtrlStat=%d, DescId=0x%04x\n",
	    txc.ds_info & 0xff,
	    MS(txc.ds_info, AR_tx_qcu_num),
	    MS(txc.ds_info, AR_ctrl_stat),
	    MS(txc.ds_info, AR_desc_id));

	/* link */
	printf("    Link 0x%08x\n", txc.ds_link);

	/* data0 */
	printf("    Data0 0x%08x Len %d\n",
	    txc.ds_data0,
	    MS(txc.ds_ctl3, AR_buf_len));

	/* data1 */
	printf("    Data1 0x%08x Len %d\n",
	    txc.ds_data1,
	    MS(txc.ds_ctl5, AR_buf_len));

	/* data2 */
	printf("    Data2 0x%08x Len %d\n",
	    txc.ds_data2,
	    MS(txc.ds_ctl7, AR_buf_len));

	/* data3 */
	printf("    Data3 0x%08x Len %d\n",
	    txc.ds_data3,
	    MS(txc.ds_ctl9, AR_buf_len));
	

	/* ctl10 */
	printf("    Desc ID=0x%04x, Chksum=0x%04x (ctl10=0x%08x)\n",
	    MS(txc.ds_ctl10, AR_tx_desc_id),
	    txc.ds_ctl10 & AR_tx_ptr_chk_sum,
	    txc.ds_ctl10);

	/* ctl11 */
	printf("    Frame Len=%d, VMF=%d, LowRxChain=%d, TxClrRetry=%d\n",
	     txc.ds_ctl11 & AR_frame_len,
	    MF(txc.ds_ctl11, AR_virt_more_frag),
	    MF(txc.ds_ctl11, AR_low_rx_chain),
	    MF(txc.ds_ctl11, AR_tx_clear_retry));
	printf("    TX power 0 = %d, RtsEna=%d, Veol=%d, ClrDstMask=%d\n",
	    MS(txc.ds_ctl11, AR_xmit_power0),
	    MF(txc.ds_ctl11, AR_rts_enable),
	    MF(txc.ds_ctl11, AR_veol),
	    MF(txc.ds_ctl11, AR_clr_dest_mask));
	printf("    TxIntrReq=%d, DestIdxValid=%d, CtsEnable=%d\n",
	    MF(txc.ds_ctl11, AR_tx_intr_req),
	    MF(txc.ds_ctl11, AR_dest_idx_valid),
	    MF(txc.ds_ctl11, AR_cts_enable));

	/* ctl12 */
	printf("    Paprd Chain Mask=0x%x, TxMore=%d, DestIdx=%d,"
	    " FrType=0x%x\n",
	    MS(txc.ds_ctl12, AR_paprd_chain_mask),
	    MF(txc.ds_ctl12, AR_tx_more),
	    MS(txc.ds_ctl12, AR_dest_idx),
	    MS(txc.ds_ctl12, AR_frame_type));
	printf("    NoAck=%d, InsertTs=%d, CorruptFcs=%d, ExtOnly=%d,"
	    " ExtAndCtl=%d\n",
	    MF(txc.ds_ctl12, AR_no_ack),
	    MF(txc.ds_ctl12, AR_insert_ts),
	    MF(txc.ds_ctl12, AR_corrupt_fcs),
	    MF(txc.ds_ctl12, AR_ext_only),
	    MF(txc.ds_ctl12, AR_ext_and_ctl));
	printf("    IsAggr=%d, MoreRifs=%d, LocMode=%d\n",
	    MF(txc.ds_ctl12, AR_is_aggr),
	    MF(txc.ds_ctl12, AR_more_rifs),
	    MF(txc.ds_ctl12, AR_loc_mode));


	/* ctl13 */
	printf("    DurUpEna=%d, Burstdur=0x%04x\n",
	    MF(txc.ds_ctl13, AR_dur_update_ena),
	    MS(txc.ds_ctl13, AR_burst_dur));
	printf("    Try0=%d, Try1=%d, Try2=%d, Try3=%d\n",
	    MS(txc.ds_ctl13, AR_xmit_data_tries0),
	    MS(txc.ds_ctl13, AR_xmit_data_tries1),
	    MS(txc.ds_ctl13, AR_xmit_data_tries2),
	    MS(txc.ds_ctl13, AR_xmit_data_tries3));

	/* ctl14 */
	printf("    rate0=0x%02x, rate1=0x%02x, rate2=0x%02x, rate3=0x%02x\n",
	    MS(txc.ds_ctl14, AR_xmit_rate0),
	    MS(txc.ds_ctl14, AR_xmit_rate1),
	    MS(txc.ds_ctl14, AR_xmit_rate2),
	    MS(txc.ds_ctl14, AR_xmit_rate3));

	/* ctl15 */
	printf("    try 0: PktDur=%d, RTS/CTS ena=%d\n",
	    MS(txc.ds_ctl15, AR_packet_dur0),
	    MF(txc.ds_ctl15, AR_rts_cts_qual0));
	printf("    try 1: PktDur=%d, RTS/CTS ena=%d\n",
	    MS(txc.ds_ctl15, AR_packet_dur1),
	    MF(txc.ds_ctl15, AR_rts_cts_qual1));

	/* ctl16 */
	printf("    try 2: PktDur=%d, RTS/CTS ena=%d\n",
	    MS(txc.ds_ctl16, AR_packet_dur2),
	    MF(txc.ds_ctl16, AR_rts_cts_qual2));
	printf("    try 3: PktDur=%d, RTS/CTS ena=%d\n",
	    MS(txc.ds_ctl16, AR_packet_dur3),
	    MF(txc.ds_ctl16, AR_rts_cts_qual3));

	/* ctl17 */
	printf("    AggrLen=%d, PadDelim=%d, EncrType=%d, TxDcApStaSel=%d\n",
	    MS(txc.ds_ctl17, AR_aggr_len),
	    MS(txc.ds_ctl17, AR_pad_delim),
	    MS(txc.ds_ctl17, AR_encr_type),
	    MF(txc.ds_ctl17, AR_tx_dc_ap_sta_sel));
	printf("    Calib=%d LDPC=%d\n",
	    MF(txc.ds_ctl17, AR_calibrating),
	    MF(txc.ds_ctl17, AR_ldpc));

	/* ctl18 */
	printf("    try 0: chainMask=0x%x, GI=%d, 2040=%d, STBC=%d\n",
	    MS(txc.ds_ctl18, AR_chain_sel0),
	    MF(txc.ds_ctl18, AR_gi0),
	    MF(txc.ds_ctl18, AR_2040_0),
	    MF(txc.ds_ctl18, AR_stbc0));
	printf("    try 1: chainMask=0x%x, GI=%d, 2040=%d, STBC=%d\n",
	    MS(txc.ds_ctl18, AR_chain_sel1),
	    MF(txc.ds_ctl18, AR_gi1),
	    MF(txc.ds_ctl18, AR_2040_1),
	    MF(txc.ds_ctl18, AR_stbc1));
	printf("    try 2: chainMask=0x%x, GI=%d, 2040=%d, STBC=%d\n",
	    MS(txc.ds_ctl18, AR_chain_sel2),
	    MF(txc.ds_ctl18, AR_gi2),
	    MF(txc.ds_ctl18, AR_2040_2),
	    MF(txc.ds_ctl18, AR_stbc2));
	printf("    try 3: chainMask=0x%x, GI=%d, 2040=%d, STBC=%d\n",
	    MS(txc.ds_ctl18, AR_chain_sel3),
	    MF(txc.ds_ctl18, AR_gi3),
	    MF(txc.ds_ctl18, AR_2040_3),
	    MF(txc.ds_ctl18, AR_stbc3));

	/* ctl19 */
	printf("    NotSounding=%d\n",
	    MF(txc.ds_ctl19, AR_not_sounding));

	printf("    try 0: ant=0x%08x, antsel=%d, ness=%d\n",
	    txc.ds_ctl19 &  AR_tx_ant0,
	    MF(txc.ds_ctl19, AR_tx_ant_sel0),
	    MS(txc.ds_ctl19, AR_ness));

	/* ctl20 */
	printf("    try 1: TxPower=%d, ant=0x%08x, antsel=%d, ness=%d\n",
	    MS(txc.ds_ctl20, AR_xmit_power1),
	    txc.ds_ctl20 &  AR_tx_ant1,
	    MF(txc.ds_ctl20, AR_tx_ant_sel1),
	    MS(txc.ds_ctl20, AR_ness1));

	/* ctl21 */
	printf("    try 2: TxPower=%d, ant=0x%08x, antsel=%d, ness=%d\n",
	    MS(txc.ds_ctl21, AR_xmit_power2),
	    txc.ds_ctl21 &  AR_tx_ant2,
	    MF(txc.ds_ctl21, AR_tx_ant_sel2),
	    MS(txc.ds_ctl21, AR_ness2));

	/* ctl22 */
	printf("    try 3: TxPower=%d, ant=0x%08x, antsel=%d, ness=%d\n",
	    MS(txc.ds_ctl22, AR_xmit_power3),
	    txc.ds_ctl22 &  AR_tx_ant3,
	    MF(txc.ds_ctl22, AR_tx_ant_sel3),
	    MS(txc.ds_ctl22, AR_ness3));

	printf("\n ------ \n");
}
Esempio n. 16
0
static void
ar5212_decode_txdesc(struct if_ath_alq_payload *a)
{
	struct ar5212_desc txc;

	/* XXX assumes txs is smaller than PAYLOAD_LEN! */
	memcpy(&txc, &a->payload, sizeof(struct ar5212_desc));

	printf("[%u.%06u] [%llu] TXD\n",
	    (unsigned int) be32toh(a->hdr.tstamp_sec),
	    (unsigned int) be32toh(a->hdr.tstamp_usec),
	    (unsigned long long) be64toh(a->hdr.threadid));

	printf("  link=0x%08x, data=0x%08x\n",
	    txc.ds_link,
	    txc.ds_data);

	/* ds_ctl0 */
	printf("    Frame Len=%d\n", txc.ds_ctl0 & AR_FrameLen);
	printf("    TX power0=%d, RtsEna=%d, Veol=%d, ClrDstMask=%d AntModeXmit=0x%02x\n",
	    MS(txc.ds_ctl0, AR_XmitPower),
	    MF(txc.ds_ctl0, AR_RTSCTSEnable),
	    MF(txc.ds_ctl0, AR_VEOL),
	    MF(txc.ds_ctl0, AR_ClearDestMask),
	    MF(txc.ds_ctl0, AR_AntModeXmit));
	printf("    TxIntrReq=%d, DestIdxValid=%d, CtsEnable=%d\n",
	    MF(txc.ds_ctl0, AR_TxInterReq),
	    MF(txc.ds_ctl0, AR_DestIdxValid),
	    MF(txc.ds_ctl0, AR_CTSEnable));

	/* ds_ctl1 */
	printf("    BufLen=%d, TxMore=%d, DestIdx=%d,"
	    " FrType=0x%x\n",
	    txc.ds_ctl1 & AR_BufLen,
	    MF(txc.ds_ctl1, AR_More),
	    MS(txc.ds_ctl1, AR_DestIdx),
	    MS(txc.ds_ctl1, AR_FrmType));
	printf("    NoAck=%d, CompProc=%d, CompIVLen=%d, CompICVLen=%d\n",
	    MF(txc.ds_ctl1, AR_NoAck),
	    MS(txc.ds_ctl1, AR_CompProc),
	    MS(txc.ds_ctl1, AR_CompIVLen),
	    MS(txc.ds_ctl1, AR_CompICVLen));

	/* ds_ctl2 */
	printf("    DurUpEna=%d, Burstdur=0x%04x\n",
	    MF(txc.ds_ctl2, AR_DurUpdateEna),
	    MS(txc.ds_ctl2, AR_RTSCTSDuration));
	printf("    Try0=%d, Try1=%d, Try2=%d, Try3=%d\n",
	    MS(txc.ds_ctl2, AR_XmitDataTries0),
	    MS(txc.ds_ctl2, AR_XmitDataTries1),
	    MS(txc.ds_ctl2, AR_XmitDataTries2),
	    MS(txc.ds_ctl2, AR_XmitDataTries3));

	/* ds_ctl3 */
	printf("    rate0=0x%02x, rate1=0x%02x, rate2=0x%02x, rate3=0x%02x\n",
	    MS(txc.ds_ctl3, AR_XmitRate0),
	    MS(txc.ds_ctl3, AR_XmitRate1),
	    MS(txc.ds_ctl3, AR_XmitRate2),
	    MS(txc.ds_ctl3, AR_XmitRate3));
	printf("    RtsCtsRate=0x%02x\n",
	    MS(txc.ds_ctl3, AR_RTSCTSRate));

	printf("\n ------ \n");
}
Esempio n. 17
0
static void
ar5212_decode_rxstatus(struct if_ath_alq_payload *a)
{
	struct ar5212_desc rxs;

	/* XXX assumes rxs is smaller than PAYLOAD_LEN! */
	memcpy(&rxs, &a->payload, sizeof(struct ar5212_desc));

	printf("[%u.%06u] [%llu] RXSTATUS: RxOK=%d TS=0x%08x\n",
	    (unsigned int) be32toh(a->hdr.tstamp_sec),
	    (unsigned int) be32toh(a->hdr.tstamp_usec),
	    (unsigned long long) be64toh(a->hdr.threadid),
	    MF(rxs.ds_rxstatus1, AR_Done),
	    MS(rxs.ds_rxstatus1, AR_RcvTimestamp));

	printf("  link=0x%08x, data=0x%08x, ctl0=0x%08x, ctl2=0x%08x\n",
	    rxs.ds_link,
	    rxs.ds_data,
	    rxs.ds_ctl0,
	    rxs.ds_ctl1);

	/* ds_rxstatus0 */
	printf("  DataLen=%d, ArMore=%d, DecompCrcError=%d, RcvRate=0x%02x\n",
	    rxs.ds_rxstatus0 & AR_DataLen,
	    MF(rxs.ds_rxstatus0, AR_More),
	    MF(rxs.ds_rxstatus0, AR_DecompCRCErr),
	    MS(rxs.ds_rxstatus0, AR_RcvRate));
	printf("  RSSI=%d, RcvAntenna=0x%x\n",
	    MS(rxs.ds_rxstatus0, AR_RcvSigStrength),
	    MS(rxs.ds_rxstatus0, AR_RcvAntenna));

	/* ds_rxstatus1 */
	printf("  RxDone=%d, RxFrameOk=%d, CrcErr=%d, DecryptCrcErr=%d\n",
	    MF(rxs.ds_rxstatus1, AR_Done),
	    MF(rxs.ds_rxstatus1, AR_FrmRcvOK),
	    MF(rxs.ds_rxstatus1, AR_CRCErr),
	    MF(rxs.ds_rxstatus1, AR_DecryptCRCErr));
	printf("  PhyErr=%d, MichaelErr=%d, KeyIdxValid=%d\n",
	    MF(rxs.ds_rxstatus1, AR_PHYErr),
	    MF(rxs.ds_rxstatus1, AR_MichaelErr),
	    MF(rxs.ds_rxstatus1, AR_KeyIdxValid));

	/* If PHY error, print that out. Otherwise, the key index */
	if (MF(rxs.ds_rxstatus1, AR_PHYErr))
		printf("  PhyErrCode=0x%02x\n",
		    MS(rxs.ds_rxstatus1, AR_PHYErrCode));
	else
		printf("  KeyIdx=0x%02x\n",
		    MS(rxs.ds_rxstatus1, AR_KeyIdx));

	printf("  KeyMiss=%d\n",
	    MF(rxs.ds_rxstatus1, AR_KeyCacheMiss));

	printf("  Timetamp: 0x%05x\n",
	    MS(rxs.ds_rxstatus1, AR_RcvTimestamp));

	printf("\n ------\n");
}
Esempio n. 18
0
static void
_cairo_test_init (cairo_test_context_t *ctx,
		  const cairo_test_context_t *parent,
		  const cairo_test_t *test,
		  const char *test_name,
		  const char *output)
{
    char *log_name;

    MF (MEMFAULT_DISABLE_FAULTS ());

#if HAVE_FEENABLEEXCEPT
    feenableexcept (FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
#endif

    ctx->test = test;
    ctx->test_name = _cairo_test_fixup_name (test_name);
    ctx->output = output;

    _cairo_test_mkdir (ctx->output);

    ctx->malloc_failure = 0;
#if HAVE_MEMFAULT
    if (getenv ("CAIRO_TEST_MALLOC_FAILURE"))
	ctx->malloc_failure = atoi (getenv ("CAIRO_TEST_MALLOC_FAILURE"));
    if (ctx->malloc_failure && ! RUNNING_ON_MEMFAULT ())
	ctx->malloc_failure = 0;
#endif

    ctx->timeout = cairo_test_timeout;
    if (getenv ("CAIRO_TEST_TIMEOUT"))
	ctx->timeout = atoi (getenv ("CAIRO_TEST_TIMEOUT"));

    xasprintf (&log_name, "%s/%s%s", ctx->output, ctx->test_name, CAIRO_TEST_LOG_SUFFIX);
    _xunlink (NULL, log_name);

    ctx->log_file = fopen (log_name, "a");
    if (ctx->log_file == NULL) {
	fprintf (stderr, "Error opening log file: %s\n", log_name);
	ctx->log_file = stderr;
    }
    free (log_name);

    ctx->ref_name = NULL;
    ctx->ref_image = NULL;
    ctx->ref_image_flattened = NULL;

    if (parent != NULL) {
	ctx->targets_to_test = parent->targets_to_test;
	ctx->num_targets = parent->num_targets;
	ctx->limited_targets = parent->limited_targets;
	ctx->own_targets = FALSE;

	ctx->srcdir = parent->srcdir;
	ctx->refdir = parent->refdir;
    } else {
	int tmp_num_targets;
	cairo_bool_t tmp_limited_targets;

	ctx->targets_to_test = cairo_boilerplate_get_targets (&tmp_num_targets, &tmp_limited_targets);
	ctx->num_targets = tmp_num_targets;
	ctx->limited_targets = tmp_limited_targets;
	ctx->own_targets = TRUE;

	ctx->srcdir = getenv ("srcdir");
	if (ctx->srcdir == NULL)
	    ctx->srcdir = ".";

	ctx->refdir = getenv ("CAIRO_REF_DIR");
    }

#ifdef HAVE_UNISTD_H
    if (*fail_face == '\0' && isatty (2)) {
	fail_face = "\033[41;37;1m";
	xfail_face = "\033[43;37;1m";
	normal_face = "\033[m";
	if (isatty (1))
	    print_fail_on_stdout = FALSE;
    }
#endif

    printf ("\nTESTING %s\n", ctx->test_name);
}
Esempio n. 19
0
static cairo_test_status_t
cairo_test_for_target (cairo_test_context_t		 *ctx,
		       const cairo_boilerplate_target_t	 *target,
		       int				  dev_offset,
		       cairo_bool_t                       similar)
{
    cairo_test_status_t status;
    cairo_surface_t *surface = NULL;
    cairo_t *cr;
    const char *empty_str = "";
    char *offset_str;
    char *base_name, *base_path;
    char *out_png_path;
    char *ref_path = NULL, *ref_png_path, *cmp_png_path = NULL;
    char *new_path = NULL, *new_png_path;
    char *xfail_path = NULL, *xfail_png_path;
    char *base_ref_png_path;
    char *base_new_png_path;
    char *base_xfail_png_path;
    char *diff_png_path;
    char *test_filename = NULL, *pass_filename = NULL, *fail_filename = NULL;
    cairo_test_status_t ret;
    cairo_content_t expected_content;
    cairo_font_options_t *font_options;
    const char *format;
    cairo_bool_t have_output = FALSE;
    cairo_bool_t have_result = FALSE;
    void *closure;
    double width, height;
    cairo_bool_t have_output_dir;
#if HAVE_MEMFAULT
    int malloc_failure_iterations = ctx->malloc_failure;
    int last_fault_count = 0;
#endif

    /* Get the strings ready that we'll need. */
    format = cairo_boilerplate_content_name (target->content);
    if (dev_offset)
	xasprintf (&offset_str, ".%d", dev_offset);
    else
	offset_str = (char *) empty_str;

    xasprintf (&base_name, "%s.%s.%s%s%s",
	       ctx->test_name,
	       target->name,
	       format,
	       similar ? ".similar" : "",
	       offset_str);

    if (offset_str != empty_str)
      free (offset_str);

    ref_png_path = cairo_test_reference_filename (ctx,
						  base_name,
						  ctx->test_name,
						  target->name,
						  target->basename,
						  format,
						  CAIRO_TEST_REF_SUFFIX,
						  CAIRO_TEST_PNG_EXTENSION);
    new_png_path = cairo_test_reference_filename (ctx,
						  base_name,
						  ctx->test_name,
						  target->name,
						  target->basename,
						  format,
						  CAIRO_TEST_NEW_SUFFIX,
						  CAIRO_TEST_PNG_EXTENSION);
    xfail_png_path = cairo_test_reference_filename (ctx,
						    base_name,
						    ctx->test_name,
						    target->name,
						    target->basename,
						    format,
						    CAIRO_TEST_XFAIL_SUFFIX,
						    CAIRO_TEST_PNG_EXTENSION);

    base_ref_png_path = cairo_test_reference_filename (ctx,
						  base_name,
						  ctx->test_name,
						  NULL, NULL,
						  format,
						  CAIRO_TEST_REF_SUFFIX,
						  CAIRO_TEST_PNG_EXTENSION);
    base_new_png_path = cairo_test_reference_filename (ctx,
						  base_name,
						  ctx->test_name,
						  NULL, NULL,
						  format,
						  CAIRO_TEST_NEW_SUFFIX,
						  CAIRO_TEST_PNG_EXTENSION);
    base_xfail_png_path = cairo_test_reference_filename (ctx,
						    base_name,
						    ctx->test_name,
						    NULL, NULL,
						    format,
						    CAIRO_TEST_XFAIL_SUFFIX,
						    CAIRO_TEST_PNG_EXTENSION);

    if (target->file_extension != NULL) {
	ref_path = cairo_test_reference_filename (ctx,
						  base_name,
						  ctx->test_name,
						  target->name,
						  target->basename,
						  format,
						  CAIRO_TEST_REF_SUFFIX,
						  target->file_extension);
	new_path = cairo_test_reference_filename (ctx,
						  base_name,
						  ctx->test_name,
						  target->name,
						  target->basename,
						  format,
						  CAIRO_TEST_NEW_SUFFIX,
						  target->file_extension);
	xfail_path = cairo_test_reference_filename (ctx,
						    base_name,
						    ctx->test_name,
						    target->name,
						    target->basename,
						    format,
						    CAIRO_TEST_XFAIL_SUFFIX,
						    target->file_extension);
    }

    have_output_dir = _cairo_test_mkdir (ctx->output);
    xasprintf (&base_path, "%s/%s",
	       have_output_dir ? ctx->output : ".",
	       base_name);
    xasprintf (&out_png_path, "%s" CAIRO_TEST_OUT_PNG, base_path);
    xasprintf (&diff_png_path, "%s" CAIRO_TEST_DIFF_PNG, base_path);

    if (ctx->test->requirements != NULL) {
	const char *required;

	required = target->is_vector ? "target=raster" : "target=vector";
	if (strstr (ctx->test->requirements, required) != NULL) {
	    cairo_test_log (ctx, "Error: Skipping for %s target %s\n",
			    target->is_vector ? "vector" : "raster",
			    target->name);
	    ret = CAIRO_TEST_UNTESTED;
	    goto UNWIND_STRINGS;
	}

	required = target->is_recording ? "target=!recording" : "target=recording";
	if (strstr (ctx->test->requirements, required) != NULL) {
	    cairo_test_log (ctx, "Error: Skipping for %s target %s\n",
			    target->is_recording ? "recording" : "non-recording",
			    target->name);
	    ret = CAIRO_TEST_UNTESTED;
	    goto UNWIND_STRINGS;
	}
    }

    width = ctx->test->width;
    height = ctx->test->height;
    if (width && height) {
	width += dev_offset;
	height += dev_offset;
    }

#if HAVE_MEMFAULT
REPEAT:
    MEMFAULT_CLEAR_FAULTS ();
    MEMFAULT_RESET_LEAKS ();
    ctx->last_fault_count = 0;
    last_fault_count = MEMFAULT_COUNT_FAULTS ();

    /* Pre-initialise fontconfig so that the configuration is loaded without
     * malloc failures (our primary goal is to test cairo fault tolerance).
     */
#if HAVE_FCINIT
    FcInit ();
#endif

    MEMFAULT_ENABLE_FAULTS ();
#endif
    have_output = FALSE;
    have_result = FALSE;

    /* Run the actual drawing code. */
    ret = CAIRO_TEST_SUCCESS;
    surface = (target->create_surface) (base_path,
					target->content,
					width, height,
					ctx->test->width + 25 * NUM_DEVICE_OFFSETS,
					ctx->test->height + 25 * NUM_DEVICE_OFFSETS,
					CAIRO_BOILERPLATE_MODE_TEST,
					&closure);
    if (surface == NULL) {
	cairo_test_log (ctx, "Error: Failed to set %s target\n", target->name);
	ret = CAIRO_TEST_UNTESTED;
	goto UNWIND_STRINGS;
    }

#if HAVE_MEMFAULT
    if (ctx->malloc_failure &&
	MEMFAULT_COUNT_FAULTS () - last_fault_count > 0 &&
	cairo_surface_status (surface) == CAIRO_STATUS_NO_MEMORY)
    {
	goto REPEAT;
    }
#endif

    if (cairo_surface_status (surface)) {
	MF (MEMFAULT_PRINT_FAULTS ());
	cairo_test_log (ctx, "Error: Created an error surface: %s\n",
			cairo_status_to_string (cairo_surface_status (surface)));
	ret = CAIRO_TEST_FAILURE;
	goto UNWIND_STRINGS;
    }

    /* Check that we created a surface of the expected type. */
    if (cairo_surface_get_type (surface) != target->expected_type) {
	MF (MEMFAULT_PRINT_FAULTS ());
	cairo_test_log (ctx, "Error: Created surface is of type %d (expected %d)\n",
			cairo_surface_get_type (surface), target->expected_type);
	ret = CAIRO_TEST_UNTESTED;
	goto UNWIND_SURFACE;
    }

    /* Check that we created a surface of the expected content,
     * (ignore the artificial CAIRO_TEST_CONTENT_COLOR_ALPHA_FLATTENED value).
     */
    expected_content = cairo_boilerplate_content (target->content);

    if (cairo_surface_get_content (surface) != expected_content) {
	MF (MEMFAULT_PRINT_FAULTS ());
	cairo_test_log (ctx, "Error: Created surface has content %d (expected %d)\n",
			cairo_surface_get_content (surface), expected_content);
	ret = CAIRO_TEST_FAILURE;
	goto UNWIND_SURFACE;
    }

    if (cairo_surface_set_user_data (surface,
				     &cairo_boilerplate_output_basename_key,
				     base_path,
				     NULL))
    {
#if HAVE_MEMFAULT
	cairo_surface_destroy (surface);

	if (target->cleanup)
	    target->cleanup (closure);

	goto REPEAT;
#else
	ret = CAIRO_TEST_FAILURE;
	goto UNWIND_SURFACE;
#endif
    }

    cairo_surface_set_device_offset (surface, dev_offset, dev_offset);

    cr = cairo_create (surface);
    if (cairo_set_user_data (cr, &_cairo_test_context_key, (void*) ctx, NULL)) {
#if HAVE_MEMFAULT
	cairo_destroy (cr);
	cairo_surface_destroy (surface);

	if (target->cleanup)
	    target->cleanup (closure);

	goto REPEAT;
#else
	ret = CAIRO_TEST_FAILURE;
	goto UNWIND_CAIRO;
#endif
    }

    if (similar)
	cairo_push_group_with_content (cr, expected_content);

    /* Clear to transparent (or black) depending on whether the target
     * surface supports alpha. */
    cairo_save (cr);
    cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
    cairo_paint (cr);
    cairo_restore (cr);

    /* Set all components of font_options to avoid backend differences
     * and reduce number of needed reference images. */
    font_options = cairo_font_options_create ();
    cairo_font_options_set_hint_style (font_options, CAIRO_HINT_STYLE_NONE);
    cairo_font_options_set_hint_metrics (font_options, CAIRO_HINT_METRICS_ON);
    cairo_font_options_set_antialias (font_options, CAIRO_ANTIALIAS_GRAY);
    cairo_set_font_options (cr, font_options);
    cairo_font_options_destroy (font_options);

    cairo_save (cr);
    alarm (ctx->timeout);
    status = (ctx->test->draw) (cr, ctx->test->width, ctx->test->height);
    alarm (0);
    cairo_restore (cr);

    if (similar) {
	cairo_pop_group_to_source (cr);
	cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
	cairo_paint (cr);
    }

#if HAVE_MEMFAULT
    MEMFAULT_DISABLE_FAULTS ();

    /* repeat test after malloc failure injection */
    if (ctx->malloc_failure &&
	MEMFAULT_COUNT_FAULTS () - last_fault_count > 0 &&
	(status == CAIRO_TEST_NO_MEMORY ||
	 cairo_status (cr) == CAIRO_STATUS_NO_MEMORY ||
	 cairo_surface_status (surface) == CAIRO_STATUS_NO_MEMORY))
    {
	cairo_destroy (cr);
	cairo_surface_destroy (surface);
	if (target->cleanup)
	    target->cleanup (closure);
	cairo_debug_reset_static_data ();
#if HAVE_FCFINI
	FcFini ();
#endif
	if (MEMFAULT_COUNT_LEAKS () > 0) {
	    MEMFAULT_PRINT_FAULTS ();
	    MEMFAULT_PRINT_LEAKS ();
	}

	goto REPEAT;
    }
#endif

    /* Then, check all the different ways it could fail. */
    if (status) {
	cairo_test_log (ctx, "Error: Function under test failed\n");
	ret = status;
	goto UNWIND_CAIRO;
    }

#if HAVE_MEMFAULT
    if (MEMFAULT_COUNT_FAULTS () - last_fault_count > 0 &&
	MEMFAULT_HAS_FAULTS ())
    {
	VALGRIND_PRINTF ("Unreported memfaults...");
	MEMFAULT_PRINT_FAULTS ();
    }
#endif

    if (target->finish_surface != NULL) {
#if HAVE_MEMFAULT
	/* We need to re-enable faults as most recording-surface processing
	 * is done during cairo_surface_finish().
	 */
	MEMFAULT_CLEAR_FAULTS ();
	last_fault_count = MEMFAULT_COUNT_FAULTS ();
	MEMFAULT_ENABLE_FAULTS ();
#endif

	/* also check for infinite loops whilst replaying */
	alarm (ctx->timeout);
	status = target->finish_surface (surface);
	alarm (0);

#if HAVE_MEMFAULT
	MEMFAULT_DISABLE_FAULTS ();

	if (ctx->malloc_failure &&
	    MEMFAULT_COUNT_FAULTS () - last_fault_count > 0 &&
	    status == CAIRO_STATUS_NO_MEMORY)
	{
	    cairo_destroy (cr);
	    cairo_surface_destroy (surface);
	    if (target->cleanup)
		target->cleanup (closure);
	    cairo_debug_reset_static_data ();
#if HAVE_FCFINI
	    FcFini ();
#endif
	    if (MEMFAULT_COUNT_LEAKS () > 0) {
		MEMFAULT_PRINT_FAULTS ();
		MEMFAULT_PRINT_LEAKS ();
	    }

	    goto REPEAT;
	}
#endif
	if (status) {
	    cairo_test_log (ctx, "Error: Failed to finish surface: %s\n",
			    cairo_status_to_string (status));
	    ret = CAIRO_TEST_FAILURE;
	    goto UNWIND_CAIRO;
	}
    }

    /* Skip image check for tests with no image (width,height == 0,0) */
    if (ctx->test->width != 0 && ctx->test->height != 0) {
	cairo_surface_t *ref_image;
	cairo_surface_t *test_image;
	cairo_surface_t *diff_image;
	buffer_diff_result_t result;
	cairo_status_t diff_status;

	if (ref_png_path == NULL) {
	    cairo_test_log (ctx, "Error: Cannot find reference image for %s\n",
			    base_name);

	    /* we may be running this test to generate reference images */
	    _xunlink (ctx, out_png_path);
	    /* be more generous as we may need to use external renderers */
	    alarm (4 * ctx->timeout);
	    test_image = target->get_image_surface (surface, 0,
		                                    ctx->test->width,
						    ctx->test->height);
	    alarm (0);
	    diff_status = cairo_surface_write_to_png (test_image, out_png_path);
	    cairo_surface_destroy (test_image);
	    if (diff_status) {
		if (cairo_surface_status (test_image) == CAIRO_STATUS_INVALID_STATUS)
		    ret = CAIRO_TEST_CRASHED;
		else
		    ret = CAIRO_TEST_FAILURE;
		cairo_test_log (ctx,
			        "Error: Failed to write output image: %s\n",
			        cairo_status_to_string (diff_status));
	    }
	    have_output = TRUE;

	    ret = CAIRO_TEST_XFAILURE;
	    goto UNWIND_CAIRO;
	}

	if (target->file_extension != NULL) { /* compare vector surfaces */
	    char *filenames[] = {
		ref_png_path,
		ref_path,
		new_png_path,
		new_path,
		xfail_png_path,
		xfail_path,
		base_ref_png_path,
		base_new_png_path,
		base_xfail_png_path,
	    };

	    xasprintf (&test_filename, "%s.out%s",
		       base_path, target->file_extension);
	    xasprintf (&pass_filename, "%s.pass%s",
		       base_path, target->file_extension);
	    xasprintf (&fail_filename, "%s.fail%s",
		       base_path, target->file_extension);

	    if (cairo_test_file_is_older (pass_filename,
					  filenames,
					  ARRAY_SIZE (filenames)))
	    {
		_xunlink (ctx, pass_filename);
	    }
	    if (cairo_test_file_is_older (fail_filename,
					  filenames,
					  ARRAY_SIZE (filenames)))
	    {
		_xunlink (ctx, fail_filename);
	    }

	    if (cairo_test_files_equal (out_png_path, ref_path)) {
		cairo_test_log (ctx, "Vector surface matches reference.\n");
		have_output = FALSE;
		ret = CAIRO_TEST_SUCCESS;
		goto UNWIND_CAIRO;
	    }
	    if (cairo_test_files_equal (out_png_path, new_path)) {
		cairo_test_log (ctx, "Vector surface matches current failure.\n");
		have_output = FALSE;
		ret = CAIRO_TEST_NEW;
		goto UNWIND_CAIRO;
	    }
	    if (cairo_test_files_equal (out_png_path, xfail_path)) {
		cairo_test_log (ctx, "Vector surface matches known failure.\n");
		have_output = FALSE;
		ret = CAIRO_TEST_XFAILURE;
		goto UNWIND_CAIRO;
	    }

	    if (cairo_test_files_equal (test_filename, pass_filename)) {
		/* identical output as last known PASS */
		cairo_test_log (ctx, "Vector surface matches last pass.\n");
		have_output = TRUE;
		ret = CAIRO_TEST_SUCCESS;
		goto UNWIND_CAIRO;
	    }
	    if (cairo_test_files_equal (test_filename, fail_filename)) {
		/* identical output as last known FAIL, fail */
		cairo_test_log (ctx, "Vector surface matches last fail.\n");
		have_result = TRUE; /* presume these were kept around as well */
		have_output = TRUE;
		ret = CAIRO_TEST_FAILURE;
		goto UNWIND_CAIRO;
	    }
	}

	/* be more generous as we may need to use external renderers */
	alarm (4 * ctx->timeout);
	test_image = target->get_image_surface (surface, 0,
					        ctx->test->width,
						ctx->test->height);
	alarm (0);
	if (cairo_surface_status (test_image)) {
	    cairo_test_log (ctx, "Error: Failed to extract image: %s\n",
			    cairo_status_to_string (cairo_surface_status (test_image)));
	    if (cairo_surface_status (test_image) == CAIRO_STATUS_INVALID_STATUS)
		ret = CAIRO_TEST_CRASHED;
	    else
		ret = CAIRO_TEST_FAILURE;
	    cairo_surface_destroy (test_image);
	    goto UNWIND_CAIRO;
	}

	_xunlink (ctx, out_png_path);
	diff_status = cairo_surface_write_to_png (test_image, out_png_path);
	if (diff_status) {
	    cairo_test_log (ctx, "Error: Failed to write output image: %s\n",
			    cairo_status_to_string (diff_status));
	    cairo_surface_destroy (test_image);
	    ret = CAIRO_TEST_FAILURE;
	    goto UNWIND_CAIRO;
	}
	have_output = TRUE;

	/* binary compare png files (no decompression) */
	if (target->file_extension == NULL) {
	    char *filenames[] = {
		ref_png_path,
		new_png_path,
		xfail_png_path,
		base_ref_png_path,
		base_new_png_path,
		base_xfail_png_path,
	    };

	    xasprintf (&test_filename, "%s", out_png_path);
	    xasprintf (&pass_filename, "%s.pass.png", base_path);
	    xasprintf (&fail_filename, "%s.fail.png", base_path);

	    if (cairo_test_file_is_older (pass_filename,
					  filenames,
					  ARRAY_SIZE (filenames)))
	    {
		_xunlink (ctx, pass_filename);
	    }
	    if (cairo_test_file_is_older (fail_filename,
					  filenames,
					  ARRAY_SIZE (filenames)))
	    {
		_xunlink (ctx, fail_filename);
	    }

	    if (cairo_test_files_equal (test_filename, pass_filename)) {
		cairo_test_log (ctx, "PNG file exactly matches last pass.\n");
                have_result = TRUE;
		cairo_surface_destroy (test_image);
		ret = CAIRO_TEST_SUCCESS;
		goto UNWIND_CAIRO;
	    }
	    if (cairo_test_files_equal (out_png_path, ref_png_path)) {
		cairo_test_log (ctx, "PNG file exactly matches reference image.\n");
                have_result = TRUE;
		cairo_surface_destroy (test_image);
		ret = CAIRO_TEST_SUCCESS;
		goto UNWIND_CAIRO;
	    }
	    if (cairo_test_files_equal (out_png_path, new_png_path)) {
		cairo_test_log (ctx, "PNG file exactly matches current failure image.\n");
                have_result = TRUE;
		cairo_surface_destroy (test_image);
		ret = CAIRO_TEST_NEW;
		goto UNWIND_CAIRO;
	    }
	    if (cairo_test_files_equal (out_png_path, xfail_png_path)) {
		cairo_test_log (ctx, "PNG file exactly matches known failure image.\n");
                have_result = TRUE;
		cairo_surface_destroy (test_image);
		ret = CAIRO_TEST_XFAILURE;
		goto UNWIND_CAIRO;
	    }
	    if (cairo_test_files_equal (test_filename, fail_filename)) {
		cairo_test_log (ctx, "PNG file exactly matches last fail.\n");
		have_result = TRUE; /* presume these were kept around as well */
		cairo_surface_destroy (test_image);
		ret = CAIRO_TEST_FAILURE;
		goto UNWIND_CAIRO;
	    }
	} else {
	    if (cairo_test_files_equal (out_png_path, ref_png_path)) {
		cairo_test_log (ctx, "PNG file exactly matches reference image.\n");
		have_result = TRUE;
		cairo_surface_destroy (test_image);
		ret = CAIRO_TEST_SUCCESS;
		goto UNWIND_CAIRO;
	    }
	    if (cairo_test_files_equal (out_png_path, new_png_path)) {
		cairo_test_log (ctx, "PNG file exactly matches current failure image.\n");
		have_result = TRUE;
		cairo_surface_destroy (test_image);
		ret = CAIRO_TEST_NEW;
		goto UNWIND_CAIRO;
	    }
	    if (cairo_test_files_equal (out_png_path, xfail_png_path)) {
		cairo_test_log (ctx, "PNG file exactly matches known failure image.\n");
		have_result = TRUE;
		cairo_surface_destroy (test_image);
		ret = CAIRO_TEST_XFAILURE;
		goto UNWIND_CAIRO;
	    }
	}

	if (cairo_test_files_equal (out_png_path, base_ref_png_path)) {
	    cairo_test_log (ctx, "PNG file exactly reference image.\n");
	    have_result = TRUE;
	    cairo_surface_destroy (test_image);
	    ret = CAIRO_TEST_SUCCESS;
	    goto UNWIND_CAIRO;
	}
	if (cairo_test_files_equal (out_png_path, base_new_png_path)) {
	    cairo_test_log (ctx, "PNG file exactly current failure image.\n");
	    have_result = TRUE;
	    cairo_surface_destroy (test_image);
	    ret = CAIRO_TEST_NEW;
	    goto UNWIND_CAIRO;
	}
	if (cairo_test_files_equal (out_png_path, base_xfail_png_path)) {
	    cairo_test_log (ctx, "PNG file exactly known failure image.\n");
	    have_result = TRUE;
	    cairo_surface_destroy (test_image);
	    ret = CAIRO_TEST_XFAILURE;
	    goto UNWIND_CAIRO;
	}

	/* first compare against the ideal reference */
	ref_image = cairo_test_get_reference_image (ctx, base_ref_png_path,
						    target->content == CAIRO_TEST_CONTENT_COLOR_ALPHA_FLATTENED);
	if (cairo_surface_status (ref_image)) {
	    cairo_test_log (ctx, "Error: Cannot open reference image for %s: %s\n",
			    base_ref_png_path,
			    cairo_status_to_string (cairo_surface_status (ref_image)));
	    cairo_surface_destroy (test_image);
	    ret = CAIRO_TEST_FAILURE;
	    goto UNWIND_CAIRO;
	}

	diff_image = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
						 ctx->test->width,
						 ctx->test->height);

	cmp_png_path = base_ref_png_path;
	diff_status = image_diff (ctx,
				  test_image, ref_image, diff_image,
				  &result);
	_xunlink (ctx, diff_png_path);
	if (diff_status ||
            image_diff_is_failure (&result, target->error_tolerance))
	{
	    /* that failed, so check against the specific backend */
	    ref_image = cairo_test_get_reference_image (ctx, ref_png_path,
							target->content == CAIRO_TEST_CONTENT_COLOR_ALPHA_FLATTENED);
	    if (cairo_surface_status (ref_image)) {
		cairo_test_log (ctx, "Error: Cannot open reference image for %s: %s\n",
				ref_png_path,
				cairo_status_to_string (cairo_surface_status (ref_image)));
		cairo_surface_destroy (test_image);
		ret = CAIRO_TEST_FAILURE;
		goto UNWIND_CAIRO;
	    }

	    cmp_png_path = ref_png_path;
	    diff_status = image_diff (ctx,
				      test_image, ref_image,
				      diff_image,
				      &result);
	    if (diff_status)
	    {
		cairo_test_log (ctx, "Error: Failed to compare images: %s\n",
				cairo_status_to_string (diff_status));
		ret = CAIRO_TEST_FAILURE;
	    }
	    else if (image_diff_is_failure (&result, target->error_tolerance))
	    {
		ret = CAIRO_TEST_FAILURE;

		diff_status = cairo_surface_write_to_png (diff_image,
							  diff_png_path);
		if (diff_status) {
		    cairo_test_log (ctx, "Error: Failed to write differences image: %s\n",
				    cairo_status_to_string (diff_status));
		} else {
		    have_result = TRUE;
		}

		cairo_test_copy_file (test_filename, fail_filename);
	    }
	    else
	    { /* success */
		cairo_test_copy_file (test_filename, pass_filename);
	    }
	}
	else
	{ /* success */
	    cairo_test_copy_file (test_filename, pass_filename);
	}

	/* If failed, compare against the current image output,
	 * and attempt to detect systematic failures.
	 */
	if (ret == CAIRO_TEST_FAILURE) {
	    char *image_out_path;

	    image_out_path =
		cairo_test_reference_filename (ctx,
					       base_name,
					       ctx->test_name,
					       "image",
					       "image",
					       format,
					       CAIRO_TEST_OUT_SUFFIX,
					       CAIRO_TEST_PNG_EXTENSION);
	    if (image_out_path != NULL) {
		if (cairo_test_files_equal (out_png_path,
					    image_out_path))
		{
		    ret = CAIRO_TEST_XFAILURE;
		}
		else
		{
		    ref_image =
			cairo_image_surface_create_from_png (image_out_path);
		    if (cairo_surface_status (ref_image) == CAIRO_STATUS_SUCCESS)
		    {
			diff_status = image_diff (ctx,
						  test_image, ref_image,
						  diff_image,
						  &result);
			if (diff_status == CAIRO_STATUS_SUCCESS &&
			    !image_diff_is_failure (&result, target->error_tolerance))
			{
			    ret = CAIRO_TEST_XFAILURE;
			}

			cairo_surface_destroy (ref_image);
		    }
		}

		free (image_out_path);
	    }
	}

	cairo_surface_destroy (test_image);
	cairo_surface_destroy (diff_image);
    }

    if (cairo_status (cr) != CAIRO_STATUS_SUCCESS) {
	cairo_test_log (ctx, "Error: Function under test left cairo status in an error state: %s\n",
			cairo_status_to_string (cairo_status (cr)));
	ret = CAIRO_TEST_ERROR;
	goto UNWIND_CAIRO;
    }

UNWIND_CAIRO:
    free (test_filename);
    free (fail_filename);
    free (pass_filename);

    test_filename = fail_filename = pass_filename = NULL;

#if HAVE_MEMFAULT
    if (ret == CAIRO_TEST_FAILURE)
	MEMFAULT_PRINT_FAULTS ();
#endif
    cairo_destroy (cr);
UNWIND_SURFACE:
    cairo_surface_destroy (surface);

    if (target->cleanup)
	target->cleanup (closure);

#if HAVE_MEMFAULT
    cairo_debug_reset_static_data ();

#if HAVE_FCFINI
    FcFini ();
#endif

    if (MEMFAULT_COUNT_LEAKS () > 0) {
	if (ret != CAIRO_TEST_FAILURE)
	    MEMFAULT_PRINT_FAULTS ();
	MEMFAULT_PRINT_LEAKS ();
    }

    if (ret == CAIRO_TEST_SUCCESS && --malloc_failure_iterations > 0)
	goto REPEAT;
#endif

    if (have_output)
	cairo_test_log (ctx, "OUTPUT: %s\n", out_png_path);

    if (have_result) {
	if (cmp_png_path == NULL) {
	    /* XXX presume we matched the normal ref last time */
	    cmp_png_path = ref_png_path;
	}
	cairo_test_log (ctx,
			"REFERENCE: %s\nDIFFERENCE: %s\n",
			cmp_png_path, diff_png_path);
    }

UNWIND_STRINGS:
    free (out_png_path);
    free (ref_png_path);
    free (base_ref_png_path);
    free (ref_path);
    free (new_png_path);
    free (base_new_png_path);
    free (new_path);
    free (xfail_png_path);
    free (base_xfail_png_path);
    free (xfail_path);
    free (diff_png_path);
    free (base_path);
    free (base_name);

    return ret;
}