summaryrefslogtreecommitdiffstats
path: root/app/test-crypto-perf/cperf.h
blob: db58228dce9e764babdf12482f5e20c22415513a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright(c) 2016-2017 Intel Corporation
 */

#ifndef _CPERF_
#define _CPERF_

#include <rte_crypto.h>

#include "cperf_ops.h"

struct cperf_options;
struct cperf_test_vector;
struct cperf_op_fns;

typedef void  *(*cperf_constructor_t)(
		struct rte_mempool *sess_mp,
		uint8_t dev_id,
		uint16_t qp_id,
		const struct cperf_options *options,
		const struct cperf_test_vector *t_vec,
		const struct cperf_op_fns *op_fns);

typedef int (*cperf_runner_t)(void *test_ctx);
typedef void (*cperf_destructor_t)(void *test_ctx);

struct cperf_test {
	cperf_constructor_t constructor;
	cperf_runner_t runner;
	cperf_destructor_t destructor;
};

#endif /* _CPERF_ */
: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ }
/*
 * Copyright (c) 2015 Cisco and/or its affiliates.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.fd.honeycomb.lisp.translate.write;

import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import io.fd.honeycomb.translate.write.WriteFailedException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.pitr.cfg.grouping.PitrCfg;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.pitr.cfg.grouping.PitrCfgBuilder;
import org.openvpp.jvpp.core.dto.LispPitrSetLocatorSet;
import org.openvpp.jvpp.core.dto.LispPitrSetLocatorSetReply;
import org.openvpp.jvpp.core.future.FutureJVppCore;


public class PitrCfgCustomizerTest {

    @Test(expected = NullPointerException.class)
    public void testWriteCurrentAttributesNullData() throws WriteFailedException {
        new PitrCfgCustomizer(mock(FutureJVppCore.class)).writeCurrentAttributes(null, null, null);
    }

    @Test(expected = NullPointerException.class)
    public void testWriteCurrentAttributesBadData() throws WriteFailedException {
        new PitrCfgCustomizer(mock(FutureJVppCore.class)).writeCurrentAttributes(null, mock(PitrCfg.class), null);
    }

    @Test
    public void testWriteCurrentAttributes() throws InterruptedException, ExecutionException, WriteFailedException {
        FutureJVppCore fakeJvpp = mock(FutureJVppCore.class);

        PitrCfgCustomizer customizer = new PitrCfgCustomizer(fakeJvpp);
        PitrCfg cfg = new PitrCfgBuilder().setLocatorSet("Locator").build();

        ArgumentCaptor<LispPitrSetLocatorSet> cfgCaptor = ArgumentCaptor.forClass(LispPitrSetLocatorSet.class);

        LispPitrSetLocatorSetReply fakeReply = new LispPitrSetLocatorSetReply();

        CompletableFuture<LispPitrSetLocatorSetReply> finalStage = new CompletableFuture<>();
        finalStage.complete(fakeReply);

        when(fakeJvpp.lispPitrSetLocatorSet(any(LispPitrSetLocatorSet.class))).thenReturn(finalStage);

        customizer.writeCurrentAttributes(null, cfg, null);
        verify(fakeJvpp, times(1)).lispPitrSetLocatorSet(cfgCaptor.capture());

        LispPitrSetLocatorSet request = cfgCaptor.getValue();
        assertEquals(1, request.isAdd);
        assertEquals("Locator", new String(request.lsName));
    }

    @Test
    public void testUpdateCurrentAttributes() throws WriteFailedException {
        FutureJVppCore fakeJvpp = mock(FutureJVppCore.class);

        PitrCfgCustomizer customizer = new PitrCfgCustomizer(fakeJvpp);
        PitrCfg cfg = new PitrCfgBuilder().setLocatorSet("Locator").build();

        ArgumentCaptor<LispPitrSetLocatorSet> cfgCaptor = ArgumentCaptor.forClass(LispPitrSetLocatorSet.class);

        LispPitrSetLocatorSetReply fakeReply = new LispPitrSetLocatorSetReply();

        CompletableFuture<LispPitrSetLocatorSetReply> finalStage = new CompletableFuture<>();
        finalStage.complete(fakeReply);

        when(fakeJvpp.lispPitrSetLocatorSet(any(LispPitrSetLocatorSet.class))).thenReturn(finalStage);

        customizer.writeCurrentAttributes(null, cfg, null);
        verify(fakeJvpp, times(1)).lispPitrSetLocatorSet(cfgCaptor.capture());

        LispPitrSetLocatorSet request = cfgCaptor.getValue();
        assertEquals(1, request.isAdd);
        assertEquals("Locator", new String(request.lsName));
    }

    @Test(expected = NullPointerException.class)
    public void testDeleteCurrentAttributesNullData() throws WriteFailedException {
        new PitrCfgCustomizer(mock(FutureJVppCore.class)).deleteCurrentAttributes(null, null, null);
    }

    @Test(expected = NullPointerException.class)
    public void testDeleteCurrentAttributesBadData() throws WriteFailedException {
        new PitrCfgCustomizer(mock(FutureJVppCore.class)).deleteCurrentAttributes(null, mock(PitrCfg.class), null);
    }

    @Test
    public void testDeleteCurrentAttributes() throws WriteFailedException, InterruptedException, ExecutionException {
        FutureJVppCore fakeJvpp = mock(FutureJVppCore.class);

        PitrCfgCustomizer customizer = new PitrCfgCustomizer(fakeJvpp);
        PitrCfg cfg = new PitrCfgBuilder().setLocatorSet("Locator").build();

        ArgumentCaptor<LispPitrSetLocatorSet> cfgCaptor = ArgumentCaptor.forClass(LispPitrSetLocatorSet.class);

        LispPitrSetLocatorSetReply fakeReply = new LispPitrSetLocatorSetReply();

        CompletableFuture<LispPitrSetLocatorSetReply> finalStage = new CompletableFuture<>();
        finalStage.complete(fakeReply);

        when(fakeJvpp.lispPitrSetLocatorSet(any(LispPitrSetLocatorSet.class))).thenReturn(finalStage);

        customizer.deleteCurrentAttributes(null, cfg, null);
        verify(fakeJvpp, times(1)).lispPitrSetLocatorSet(cfgCaptor.capture());

        LispPitrSetLocatorSet request = cfgCaptor.getValue();
        assertEquals(0, request.isAdd);
        assertEquals("Locator", new String(request.lsName));
    }

}